Remember last selected tab in share dialog

This commit is contained in:
fkloft
2013-07-30 23:13:24 +02:00
parent 63474d4c40
commit 88d87f1776
2 changed files with 27 additions and 4 deletions

View File

@ -107,7 +107,7 @@ public class IITC_Mobile extends Activity {
return;
}
// no reload needed
if (key.equals("pref_press_twice_to_exit"))
if (key.equals("pref_press_twice_to_exit") || key.equals("pref_share_selected_tab"))
return;
reload_needed = true;

View File

@ -3,8 +3,10 @@ package com.cradle.iitc_mobile.share;
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
@ -15,6 +17,7 @@ import com.cradle.iitc_mobile.R;
public class ShareActivity extends FragmentActivity implements ActionBar.TabListener {
private boolean mIsPortal;
private String mLl;
private SharedPreferences mSharedPrefs = null;
private String mTitle;
private int mZoom;
IntentFragmentAdapter mFragmentAdapter;
@ -38,6 +41,17 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
return url;
}
private void setSelected(int position) {
// Activity not fully loaded yet (may occur during tab creation)
if (mSharedPrefs == null)
return;
mSharedPrefs
.edit()
.putInt("pref_share_selected_tab", position)
.apply();
}
private void setupIntents() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
@ -55,8 +69,6 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share);
@ -81,6 +93,7 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
setSelected(position);
}
});
@ -93,6 +106,14 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
.setIcon(fragment.getIcon())
.setTabListener(this));
}
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
int selected = mSharedPrefs.getInt("pref_share_selected_tab", 0);
if (selected < mFragmentAdapter.getCount())
{
mViewPager.setCurrentItem(selected);
actionBar.setSelectedNavigationItem(selected);
}
}
@Override
@ -111,7 +132,9 @@ public class ShareActivity extends FragmentActivity implements ActionBar.TabList
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
mViewPager.setCurrentItem(tab.getPosition());
int position = tab.getPosition();
mViewPager.setCurrentItem(position);
setSelected(position);
}
@Override