2013-06-25 04:02:30 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
2014-12-15 20:25:55 +00:00
|
|
|
import android.support.annotation.NonNull;
|
2013-06-25 04:02:30 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
|
import android.support.v4.view.ViewPager;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
|
import android.view.MenuItem;
|
2014-01-08 22:29:05 +00:00
|
|
|
|
2014-11-03 23:16:04 +00:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2015-01-12 00:24:19 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2013-06-25 04:02:30 +00:00
|
|
|
|
|
|
|
|
2014-06-29 03:40:57 +00:00
|
|
|
public class ImportExportActivity extends PassphraseRequiredActionBarActivity {
|
2013-06-25 04:02:30 +00:00
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
private MasterSecret masterSecret;
|
2013-06-25 04:02:30 +00:00
|
|
|
private TabPagerAdapter tabPagerAdapter;
|
2014-12-15 20:25:55 +00:00
|
|
|
private ViewPager viewPager;
|
2013-06-25 04:02:30 +00:00
|
|
|
|
2015-01-12 00:24:19 +00:00
|
|
|
private DynamicTheme dynamicTheme = new DynamicTheme();
|
|
|
|
|
2013-06-25 04:02:30 +00:00
|
|
|
@Override
|
2014-12-15 20:25:55 +00:00
|
|
|
protected void onPreCreate() {
|
2015-01-12 00:24:19 +00:00
|
|
|
dynamicTheme.onCreate(this);
|
2014-12-15 20:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState, @NonNull MasterSecret masterSecret) {
|
|
|
|
this.masterSecret = masterSecret;
|
2013-06-25 04:02:30 +00:00
|
|
|
setContentView(R.layout.import_export_activity);
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
initializeResources();
|
|
|
|
initializeViewPager();
|
|
|
|
initializeTabs();
|
|
|
|
}
|
|
|
|
|
2015-01-12 00:24:19 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
2013-06-25 04:02:30 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home: finish(); return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeResources() {
|
|
|
|
this.viewPager = (ViewPager) findViewById(R.id.import_export_pager);
|
|
|
|
this.tabPagerAdapter = new TabPagerAdapter(getSupportFragmentManager());
|
|
|
|
|
|
|
|
viewPager.setAdapter(tabPagerAdapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeViewPager() {
|
|
|
|
viewPager.setAdapter(tabPagerAdapter);
|
|
|
|
viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onPageSelected(int position) {
|
|
|
|
getSupportActionBar().setSelectedNavigationItem(position);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeTabs() {
|
|
|
|
final ActionBar actionBar = getSupportActionBar();
|
|
|
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
|
|
|
|
|
|
|
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
|
|
|
|
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
|
|
|
|
viewPager.setCurrentItem(tab.getPosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {}
|
|
|
|
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {}
|
|
|
|
};
|
|
|
|
|
2014-06-22 23:29:05 +00:00
|
|
|
actionBar.addTab(actionBar.newTab().setText(R.string.ImportExportActivity_import).setTabListener(tabListener));
|
|
|
|
actionBar.addTab(actionBar.newTab().setText(R.string.ImportExportActivity_export).setTabListener(tabListener));
|
2013-06-25 04:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TabPagerAdapter extends FragmentStatePagerAdapter {
|
|
|
|
private final ImportFragment importFragment;
|
|
|
|
private final ExportFragment exportFragment;
|
|
|
|
|
|
|
|
public TabPagerAdapter(FragmentManager fragmentManager) {
|
|
|
|
super(fragmentManager);
|
|
|
|
|
|
|
|
this.importFragment = new ImportFragment();
|
|
|
|
this.exportFragment = new ExportFragment();
|
|
|
|
this.importFragment.setMasterSecret(masterSecret);
|
|
|
|
this.exportFragment.setMasterSecret(masterSecret);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Fragment getItem(int i) {
|
|
|
|
if (i == 0) return importFragment;
|
|
|
|
else return exportFragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CharSequence getPageTitle(int i) {
|
2014-06-22 23:29:05 +00:00
|
|
|
if (i == 0) return getString(R.string.ImportExportActivity_import);
|
|
|
|
else return getString(R.string.ImportExportActivity_export);
|
2013-06-25 04:02:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
}
|