Fix the SAM lifecycle error. Migrate the other MagicIndicator components
This commit is contained in:
@ -7,6 +7,7 @@ import android.content.Intent;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
//import android.support.v4.app.Fragment;
|
//import android.support.v4.app.Fragment;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
//import android.support.v4.app.FragmentManager;
|
//import android.support.v4.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
@ -27,18 +28,27 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
//import com.viewpagerindicator.TitlePageIndicator;
|
import net.lucode.hackware.magicindicator.MagicIndicator;
|
||||||
|
import net.lucode.hackware.magicindicator.ViewPagerHelper;
|
||||||
|
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
|
||||||
|
|
||||||
import net.i2p.android.router.R;
|
import net.i2p.android.router.R;
|
||||||
import net.i2p.android.router.util.NamingServiceUtil;
|
import net.i2p.android.router.util.NamingServiceUtil;
|
||||||
import net.i2p.android.router.util.Util;
|
import net.i2p.android.router.util.Util;
|
||||||
import net.i2p.client.naming.NamingService;
|
import net.i2p.client.naming.NamingService;
|
||||||
|
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
|
||||||
|
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
|
||||||
|
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
|
||||||
|
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
|
||||||
|
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;
|
||||||
|
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;
|
||||||
|
|
||||||
public class AddressbookContainer extends Fragment
|
public class AddressbookContainer extends Fragment
|
||||||
implements AddressbookFragment.OnAddressSelectedListener,
|
implements AddressbookFragment.OnAddressSelectedListener,
|
||||||
SearchView.OnQueryTextListener {
|
SearchView.OnQueryTextListener {
|
||||||
public static final int ADD_WIZARD_REQUEST = 1;
|
public static final int ADD_WIZARD_REQUEST = 1;
|
||||||
public static final String ADD_WIZARD_DATA = "add_wizard_data";
|
public static final String ADD_WIZARD_DATA = "add_wizard_data";
|
||||||
|
private MagicIndicator mPageIndicator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the container is in two-pane mode, i.e. running on a tablet
|
* Whether or not the container is in two-pane mode, i.e. running on a tablet
|
||||||
@ -48,7 +58,6 @@ public class AddressbookContainer extends Fragment
|
|||||||
|
|
||||||
ViewPager mViewPager;
|
ViewPager mViewPager;
|
||||||
FragmentPagerAdapter mFragPagerAdapter;
|
FragmentPagerAdapter mFragPagerAdapter;
|
||||||
|
|
||||||
private static final String FRAGMENT_ROUTER = "router_fragment";
|
private static final String FRAGMENT_ROUTER = "router_fragment";
|
||||||
private static final String FRAGMENT_PRIVATE = "private_fragment";
|
private static final String FRAGMENT_PRIVATE = "private_fragment";
|
||||||
private static final int FRAGMENT_ID_ROUTER = 0;
|
private static final int FRAGMENT_ID_ROUTER = 0;
|
||||||
@ -74,6 +83,17 @@ public class AddressbookContainer extends Fragment
|
|||||||
mTwoPane = true;
|
mTwoPane = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mTwoPane) {
|
||||||
|
// Initialize ViewPager and adapter first
|
||||||
|
mViewPager = (ViewPager) v.findViewById(R.id.pager);
|
||||||
|
mFragPagerAdapter = new AddressbookPagerAdapter(getActivity(), getChildFragmentManager());
|
||||||
|
mViewPager.setAdapter(mFragPagerAdapter);
|
||||||
|
|
||||||
|
// Then set up MagicIndicator
|
||||||
|
mPageIndicator = v.findViewById(R.id.magic_indicator);
|
||||||
|
setupMagicIndicator();
|
||||||
|
}
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mRouterFrag = (AddressbookFragment) getChildFragmentManager().getFragment(
|
mRouterFrag = (AddressbookFragment) getChildFragmentManager().getFragment(
|
||||||
savedInstanceState, FRAGMENT_ROUTER);
|
savedInstanceState, FRAGMENT_ROUTER);
|
||||||
@ -97,14 +117,6 @@ public class AddressbookContainer extends Fragment
|
|||||||
ft.commit();
|
ft.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mTwoPane) {
|
|
||||||
mViewPager = (ViewPager) v.findViewById(R.id.pager);
|
|
||||||
//TitlePageIndicator pageIndicator = (TitlePageIndicator) v.findViewById(R.id.page_indicator);
|
|
||||||
mFragPagerAdapter = new AddressbookPagerAdapter(getActivity(), getChildFragmentManager());
|
|
||||||
mViewPager.setAdapter(mFragPagerAdapter);
|
|
||||||
//pageIndicator.setViewPager(mViewPager);
|
|
||||||
}
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,4 +269,38 @@ public class AddressbookContainer extends Fragment
|
|||||||
if (mPrivateFrag != null)
|
if (mPrivateFrag != null)
|
||||||
mPrivateFrag.filterAddresses(query);
|
mPrivateFrag.filterAddresses(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupMagicIndicator() {
|
||||||
|
if (mPageIndicator == null || mFragPagerAdapter == null || mViewPager == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonNavigator commonNavigator = new CommonNavigator(getContext());
|
||||||
|
commonNavigator.setAdapter(new CommonNavigatorAdapter() {
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return mFragPagerAdapter.getCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPagerTitleView getTitleView(Context context, int index) {
|
||||||
|
SimplePagerTitleView titleView = new ColorTransitionPagerTitleView(context);
|
||||||
|
titleView.setText(mFragPagerAdapter.getPageTitle(index));
|
||||||
|
titleView.setNormalColor(ContextCompat.getColor(context, R.color.primary_text_disabled_material_dark));
|
||||||
|
titleView.setSelectedColor(ContextCompat.getColor(context, R.color.primary_text_default_material_dark));
|
||||||
|
titleView.setOnClickListener(v -> mViewPager.setCurrentItem(index));
|
||||||
|
return titleView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPagerIndicator getIndicator(Context context) {
|
||||||
|
LinePagerIndicator indicator = new LinePagerIndicator(context);
|
||||||
|
indicator.setColors(ContextCompat.getColor(context, R.color.primary));
|
||||||
|
return indicator;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mPageIndicator.setNavigator(commonNavigator);
|
||||||
|
ViewPagerHelper.bind(mPageIndicator, mViewPager);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,9 @@ import android.app.PendingIntent;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
//import android.support.v7.app.AppCompatActivity;
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import net.i2p.android.I2PActivity;
|
import net.i2p.android.I2PActivity;
|
||||||
@ -23,6 +25,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements SAMSecureSessionInterface on Android platforms using a Toast
|
* Implements SAMSecureSessionInterface on Android platforms using a Toast
|
||||||
* as the interactive channel.
|
* as the interactive channel.
|
||||||
@ -46,12 +49,35 @@ public class AndroidSAMSecureSession extends AppCompatActivity implements SAMSec
|
|||||||
results.put(clientId, 1);
|
results.put(clientId, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AndroidSAMSecureSession(Context ctx, RouterService rCtx, StatusBar statusBar) {
|
private AndroidSAMSecureSession(Context ctx, RouterService rCtx, StatusBar statusBar) {
|
||||||
mCtx = ctx;
|
mCtx = ctx;
|
||||||
_routerService = rCtx;
|
_routerService = rCtx;
|
||||||
_statusBar = statusBar;
|
_statusBar = statusBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AndroidSAMSecureSession create(Context ctx, RouterService rCtx, StatusBar statusBar) {
|
||||||
|
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
|
||||||
|
// We're on the main thread, create directly
|
||||||
|
return new AndroidSAMSecureSession(ctx, rCtx, statusBar);
|
||||||
|
} else {
|
||||||
|
// We're not on the main thread, post to main thread
|
||||||
|
final AndroidSAMSecureSession[] result = new AndroidSAMSecureSession[1];
|
||||||
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
new Handler(Looper.getMainLooper()).post(() -> {
|
||||||
|
result[0] = new AndroidSAMSecureSession(ctx, rCtx, statusBar);
|
||||||
|
latch.countDown();
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
latch.await();
|
||||||
|
return result[0];
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException("Failed to create AndroidSAMSecureSession", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void waitForResult(String clientId) {
|
private void waitForResult(String clientId) {
|
||||||
for (int i=0;i<60;i++) {
|
for (int i=0;i<60;i++) {
|
||||||
try {
|
try {
|
||||||
|
@ -180,7 +180,8 @@ class LoadClientsJob extends JobImpl {
|
|||||||
try {
|
try {
|
||||||
Util.i("Starting the SAM API");
|
Util.i("Starting the SAM API");
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
AndroidSAMSecureSession _androidSecureSession = new AndroidSAMSecureSession(mCtx, _routerService, _statusBar);
|
//AndroidSAMSecureSession _androidSecureSession = new AndroidSAMSecureSession(mCtx, _routerService, _statusBar);
|
||||||
|
AndroidSAMSecureSession _androidSecureSession = AndroidSAMSecureSession.create(mCtx, _routerService, _statusBar);
|
||||||
SAMSecureSessionInterface _secureSession = _androidSecureSession;
|
SAMSecureSessionInterface _secureSession = _androidSecureSession;
|
||||||
SAM_BRIDGE = new SAMBridge("127.0.0.1",
|
SAM_BRIDGE = new SAMBridge("127.0.0.1",
|
||||||
7656,
|
7656,
|
||||||
|
@ -5,7 +5,12 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<!-- The main content view -->
|
<net.lucode.hackware.magicindicator.MagicIndicator
|
||||||
|
android:id="@+id/magic_indicator"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/pager_indicator_height"
|
||||||
|
android:theme="@style/MagicIndicator" />
|
||||||
|
|
||||||
<androidx.viewpager.widget.ViewPager
|
<androidx.viewpager.widget.ViewPager
|
||||||
android:id="@+id/pager"
|
android:id="@+id/pager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
android:title="@string/action_search"
|
android:title="@string/action_search"
|
||||||
android:icon="@drawable/ic_search_white_24dp"
|
android:icon="@drawable/ic_search_white_24dp"
|
||||||
i2pandroid:showAsAction="ifRoom|collapseActionView"
|
i2pandroid:showAsAction="ifRoom|collapseActionView"
|
||||||
i2pandroid:actionViewClass="android.support.v7.widget.SearchView" />
|
i2pandroid:actionViewClass="androidx.appcompat.widget.SearchView" />
|
||||||
</menu>
|
</menu>
|
Reference in New Issue
Block a user