Skip to content

Commit

Permalink
Merge pull request ankidroid#424 from timrae/studyOptionsFix
Browse files Browse the repository at this point in the history
fix issue 2164 and issue 2182
  • Loading branch information
nicolas-raoul committed Jul 17, 2014
2 parents eb643c2 + 5074353 commit 73b3433
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 47 deletions.
16 changes: 10 additions & 6 deletions src/com/ichi2/anki/DeckPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
import java.util.Locale;
import java.util.TreeSet;

public class DeckPicker extends NavigationDrawerActivity {
public class DeckPicker extends NavigationDrawerActivity implements StudyOptionsFragment.OnStudyOptionsReloadListener {

public static final int CRAM_DECK_FRAGMENT = -1;

Expand Down Expand Up @@ -252,7 +252,7 @@ public void onClick(DialogInterface dialog, int item) {
mCurrentDid = Long.parseLong(mDeckList.get(mContextMenuPosition).get("did"));
AnkiDroidApp.getCol().getDecks().select(mCurrentDid);
if (mFragmented) {
setStudyContentView(mCurrentDid, null);
loadStudyOptionsFragment(mCurrentDid, null);
}
// open deck options
if (AnkiDroidApp.getCol().getDecks().isDyn(mCurrentDid)){
Expand Down Expand Up @@ -2204,10 +2204,14 @@ private void finishWithAnimation() {
// CUSTOM METHODS
// ----------------------------------------------------------------------------

public void setStudyContentView(long deckId, Bundle cramConfig) {
StudyOptionsFragment details = StudyOptionsFragment.newInstance(deckId, false, cramConfig);
public void loadStudyOptionsFragment() {
loadStudyOptionsFragment(0, null);
}


public void loadStudyOptionsFragment(long deckId, Bundle cramConfig) {
StudyOptionsFragment details = StudyOptionsFragment.newInstance(deckId, cramConfig);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
// ft.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
ft.replace(R.id.studyoptions_fragment, details);
ft.commit();
Expand Down Expand Up @@ -2738,7 +2742,7 @@ private void openStudyOptions(long deckId) {

private void openStudyOptions(long deckId, Bundle cramInitialConfig) {
if (mFragmented) {
setStudyContentView(deckId, cramInitialConfig);
loadStudyOptionsFragment(deckId, cramInitialConfig);
} else {
mDontSaveOnStop = true;
Intent intent = new Intent();
Expand Down
20 changes: 8 additions & 12 deletions src/com/ichi2/anki/StudyOptionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
Expand All @@ -35,12 +34,11 @@

import com.ichi2.anim.ActivityTransitionAnimation;
import com.ichi2.anki.receiver.SdCardReceiver;
import com.ichi2.libanki.Utils;
import com.ichi2.themes.StyledOpenCollectionDialog;
import com.ichi2.themes.Themes;
import com.ichi2.widget.WidgetStatus;

public class StudyOptionsActivity extends NavigationDrawerActivity {
public class StudyOptionsActivity extends NavigationDrawerActivity implements StudyOptionsFragment.OnStudyOptionsReloadListener {

private StudyOptionsFragment mCurrentFragment;

Expand All @@ -62,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
mDrawerList = (ListView) findViewById(R.id.studyoptions_left_drawer);
initNavigationDrawer();
if (savedInstanceState == null) {
loadContent(getIntent().getBooleanExtra("onlyFnsMsg", false));
loadStudyOptionsFragment();
}
registerExternalStorageListener();
}
Expand All @@ -77,22 +75,20 @@ public boolean onPrepareOptionsMenu(Menu menu){
return true;
}

public void loadContent(boolean onlyFnsMsg) {
loadContent(onlyFnsMsg, null);
public void loadStudyOptionsFragment() {
loadStudyOptionsFragment(0, null);
}


public void loadContent(boolean onlyFnsMsg, Bundle cramConfig) {
mCurrentFragment = StudyOptionsFragment.newInstance(0, false, null);
public void loadStudyOptionsFragment(long deckId, Bundle cramConfig) {
mCurrentFragment = StudyOptionsFragment.newInstance(deckId, null);
Bundle args = getIntent().getExtras();
if (onlyFnsMsg) {
args.putBoolean("onlyFnsMsg", onlyFnsMsg);
}

if (cramConfig != null) {
args.putBundle("cramInitialConfig", cramConfig);
}
mCurrentFragment.setArguments(args);
getSupportFragmentManager().beginTransaction().add(R.id.studyoptions_frame, mCurrentFragment).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.studyoptions_frame, mCurrentFragment).commit();
}

@Override
Expand Down
54 changes: 25 additions & 29 deletions src/com/ichi2/anki/StudyOptionsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
import java.util.Locale;

public class StudyOptionsFragment extends Fragment {

// Container Activity must implement this interface
public interface OnStudyOptionsReloadListener {
public void loadStudyOptionsFragment(long deckId, Bundle cramConfig);
public void loadStudyOptionsFragment();
}

/**
* Available options performed by other activities
Expand Down Expand Up @@ -241,13 +247,12 @@ private void rebuildCramDeck() {
}


public static StudyOptionsFragment newInstance(long deckId, boolean onlyFnsMsg, Bundle cramInitialConfig) {
public static StudyOptionsFragment newInstance(long deckId, Bundle cramInitialConfig) {
StudyOptionsFragment f = new StudyOptionsFragment();

// Supply index input as an argument.
Bundle args = new Bundle();
args.putLong("deckId", deckId);
args.putBoolean("onlyFnsMsg", onlyFnsMsg);
args.putBundle("cramInitialConfig", cramInitialConfig);
f.setArguments(args);

Expand Down Expand Up @@ -294,7 +299,7 @@ public boolean onTouch(View v, MotionEvent event) {
};
}

if (getArguments().getBoolean("onlyFnsMsg")) {
if (noDeckCounts()) {
prepareCongratsView();
} else {
// clear undo if new deck is opened (do not clear if only congrats msg is shown)
Expand Down Expand Up @@ -449,7 +454,7 @@ public void onPostExecute(DeckTask.TaskData result) {
if (!AnkiDroidApp.colIsOpen()) {
closeStudyOptions();
} else if (!mFragmented) {
((StudyOptionsActivity) getActivity()).loadContent(false);
((OnStudyOptionsReloadListener) getActivity()).loadStudyOptionsFragment();
}
}

Expand Down Expand Up @@ -930,16 +935,6 @@ public void onClick(DialogInterface dialog, int which) {
ar.getJSONArray(0).put(2, terms[2]);
dyn.put("resched", resched);

if (mFragmented) {
Bundle config = new Bundle();
config.putString("searchSuffix", "'deck:" + dyn.getString("name") + "'");
initAllContentViews(getLayoutInflater(config));
finishCongrats();
} else {
// Load a new fragment with the filtered deck view. The config passed is null, so it uses the
// current deck. The deck we just created is internally set as the current deck.
((StudyOptionsActivity) getActivity()).loadContent(false, null);
}

// Initial rebuild
mProgressDialog = StyledProgressDialog.show(getActivity(), "",
Expand Down Expand Up @@ -1219,6 +1214,17 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
}
}
}

private void dismissProgressDialog() {
// for rebuilding cram decks
if (mProgressDialog != null && mProgressDialog.isShowing()) {
try {
mProgressDialog.dismiss();
} catch (Exception e) {
Log.e(AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
}
}
}


public SharedPreferences restorePreferences() {
Expand All @@ -1231,7 +1237,8 @@ public SharedPreferences restorePreferences() {
DeckTask.TaskListener mRebuildCustomStudyListener = new DeckTask.TaskListener() {
@Override
public void onPostExecute(TaskData result) {
resetAndUpdateValuesFromDeck();
dismissProgressDialog();
((OnStudyOptionsReloadListener) getActivity()).loadStudyOptionsFragment();
}


Expand Down Expand Up @@ -1341,13 +1348,7 @@ public void run() {
}

// for rebuilding cram decks
if (mProgressDialog != null && mProgressDialog.isShowing()) {
try {
mProgressDialog.dismiss();
} catch (Exception e) {
Log.e(AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
}
}
dismissProgressDialog();
}


Expand All @@ -1372,13 +1373,8 @@ public void onCancelled() {

@Override
public void onPostExecute(DeckTask.TaskData result) {
if (mProgressDialog.isShowing()) {
try {
mProgressDialog.dismiss();
} catch (Exception e) {
Log.e(AnkiDroidApp.TAG, "onPostExecute - Dialog dismiss Exception = " + e.getMessage());
}
}
dismissProgressDialog();

if (result.getBoolean()) {
// if (mStatisticType == Statistics.TYPE_DECK_SUMMARY) {
// Statistics.showDeckSummary(getActivity());
Expand Down

0 comments on commit 73b3433

Please sign in to comment.