|
|
|
@ -24,6 +24,7 @@ import java.io.File;
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import fr.android.pointspermis.captcha.Captcha; |
|
|
|
|
import fr.android.pointspermis.settings.ConfigActivity; |
|
|
|
|
import fr.android.pointspermis.settings.SettingsActivity; |
|
|
|
|
import fr.android.pointspermis.tools.AssetsTools; |
|
|
|
|
import fr.android.pointspermis.web.WebTask; |
|
|
|
@ -32,8 +33,14 @@ import fr.android.pointspermis.web.WebTask;
|
|
|
|
|
public class MainActivity extends Activity |
|
|
|
|
implements NavigationDrawerFragment.NavigationDrawerCallbacks { |
|
|
|
|
|
|
|
|
|
public final static String SOLDE_KEY = "solde"; |
|
|
|
|
public final static String USERNAME_KEY = "username"; |
|
|
|
|
public final static String BIRTHDAY_KEY = "birthday"; |
|
|
|
|
|
|
|
|
|
private final Context context = this; |
|
|
|
|
|
|
|
|
|
private ActionBar actionBar; |
|
|
|
|
|
|
|
|
|
private WebTask webform; |
|
|
|
|
|
|
|
|
|
private SharedPreferences prefs; |
|
|
|
@ -43,17 +50,14 @@ public class MainActivity extends Activity
|
|
|
|
|
private String username; |
|
|
|
|
private String birthday; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Fragment managing the behaviors, interactions and presentation of the navigation drawer. |
|
|
|
|
*/ |
|
|
|
|
private FragmentManager fragmentManager; |
|
|
|
|
private NavigationDrawerFragment mNavigationDrawerFragment; |
|
|
|
|
|
|
|
|
|
private PlaceholderFragment mPlaceholderFrament; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Used to store the last screen title. For use in {@link #restoreActionBar()}. |
|
|
|
|
*/ |
|
|
|
|
private CharSequence mTitle; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
@ -69,23 +73,36 @@ public class MainActivity extends Activity
|
|
|
|
|
// Copy tesseract data to app-specific internal storage (language stuff)
|
|
|
|
|
copyTesseractData(); |
|
|
|
|
|
|
|
|
|
mNavigationDrawerFragment = (NavigationDrawerFragment) |
|
|
|
|
getFragmentManager().findFragmentById(R.id.navigation_drawer); |
|
|
|
|
mTitle = getTitle(); |
|
|
|
|
// Get actionBar
|
|
|
|
|
actionBar = getActionBar(); |
|
|
|
|
|
|
|
|
|
// Get fragment manager
|
|
|
|
|
fragmentManager = getFragmentManager(); |
|
|
|
|
|
|
|
|
|
// Set up the drawer.
|
|
|
|
|
mNavigationDrawerFragment = (NavigationDrawerFragment) |
|
|
|
|
fragmentManager.findFragmentById(R.id.navigation_drawer); |
|
|
|
|
mNavigationDrawerFragment.setUp( |
|
|
|
|
R.id.navigation_drawer, |
|
|
|
|
(DrawerLayout) findViewById(R.id.drawer_layout)); |
|
|
|
|
|
|
|
|
|
(DrawerLayout) findViewById(R.id.drawer_layout) |
|
|
|
|
); |
|
|
|
|
// Load prefs
|
|
|
|
|
prefs = getSharedPreferences("fr.android.pointspermis", MODE_PRIVATE); |
|
|
|
|
editor = prefs.edit(); |
|
|
|
|
|
|
|
|
|
// Try to get saved values
|
|
|
|
|
solde = prefs.getString("solde", ""); |
|
|
|
|
username = prefs.getString("username", ""); |
|
|
|
|
birthday = prefs.getString("birthday", ""); |
|
|
|
|
solde = prefs.getString(SOLDE_KEY, " "); |
|
|
|
|
username = prefs.getString(USERNAME_KEY, ""); |
|
|
|
|
birthday = prefs.getString(BIRTHDAY_KEY, ""); |
|
|
|
|
|
|
|
|
|
// Set the main fragment with args
|
|
|
|
|
mPlaceholderFrament = new PlaceholderFragment(); |
|
|
|
|
Bundle args = new Bundle(); |
|
|
|
|
args.putString(SOLDE_KEY, solde); |
|
|
|
|
args.putString(USERNAME_KEY, username); |
|
|
|
|
args.putString(BIRTHDAY_KEY, birthday); |
|
|
|
|
mPlaceholderFrament.setArguments(args); |
|
|
|
|
fragmentManager.beginTransaction().replace(R.id.container, mPlaceholderFrament).commit(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void copyTesseractData() { |
|
|
|
@ -115,35 +132,30 @@ public class MainActivity extends Activity
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onNavigationDrawerItemSelected(int position) { |
|
|
|
|
// update the main content by replacing fragments
|
|
|
|
|
FragmentManager fragmentManager = getFragmentManager(); |
|
|
|
|
|
|
|
|
|
/* update the main content by replacing fragments |
|
|
|
|
mPlaceholderFrament = PlaceholderFragment.newInstance(position + 1); |
|
|
|
|
fragmentManager.beginTransaction().replace(R.id.container, mPlaceholderFrament).commit();*/ |
|
|
|
|
|
|
|
|
|
fragmentManager.beginTransaction().replace(R.id.container, mPlaceholderFrament).commit(); |
|
|
|
|
// Manage actions on drawer's clicks
|
|
|
|
|
if (position == 0) { |
|
|
|
|
Intent i = new Intent(this, ConfigActivity.class); |
|
|
|
|
startActivity(i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void onSectionAttached(int number) { |
|
|
|
|
switch (number) { |
|
|
|
|
case 1: |
|
|
|
|
mTitle = getString(R.string.title_home); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
mTitle = getString(R.string.title_settings); |
|
|
|
|
if (position == 1) { |
|
|
|
|
Intent i = new Intent(this, SettingsActivity.class); |
|
|
|
|
startActivity(i); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (position == 2) { |
|
|
|
|
quit(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void restoreActionBar() { |
|
|
|
|
ActionBar actionBar = getActionBar(); |
|
|
|
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
|
|
|
|
actionBar.setDisplayShowTitleEnabled(true); |
|
|
|
|
actionBar.setTitle(mTitle); |
|
|
|
|
actionBar.setTitle(R.string.app_name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
|
|
if (!mNavigationDrawerFragment.isDrawerOpen()) { |
|
|
|
@ -165,6 +177,12 @@ public class MainActivity extends Activity
|
|
|
|
|
int id = item.getItemId(); |
|
|
|
|
|
|
|
|
|
//noinspection SimplifiableIfStatement
|
|
|
|
|
if (id == R.id.action_config) { |
|
|
|
|
Intent i = new Intent(this, ConfigActivity.class); |
|
|
|
|
startActivity(i); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (id == R.id.action_settings) { |
|
|
|
|
Intent i = new Intent(this, SettingsActivity.class); |
|
|
|
|
startActivity(i); |
|
|
|
@ -175,10 +193,10 @@ public class MainActivity extends Activity
|
|
|
|
|
|
|
|
|
|
// Initialize and execute the WebForm async task
|
|
|
|
|
webform = new WebTask(context, MainActivity.this); |
|
|
|
|
webform.execute(prefs.getString(SettingsActivity.DOSSIER1_KEY, ""), |
|
|
|
|
prefs.getString(SettingsActivity.DOSSIER2_KEY, ""), |
|
|
|
|
prefs.getString(SettingsActivity.DOSSIER3_KEY, ""), |
|
|
|
|
prefs.getString(SettingsActivity.CODE_KEY, "") |
|
|
|
|
webform.execute(prefs.getString(ConfigActivity.DOSSIER1_KEY, ""), |
|
|
|
|
prefs.getString(ConfigActivity.DOSSIER2_KEY, ""), |
|
|
|
|
prefs.getString(ConfigActivity.DOSSIER3_KEY, ""), |
|
|
|
|
prefs.getString(ConfigActivity.CODE_KEY, "") |
|
|
|
|
); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -190,67 +208,14 @@ public class MainActivity extends Activity
|
|
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* A placeholder fragment containing a simple view. |
|
|
|
|
*/ |
|
|
|
|
public static class PlaceholderFragment extends Fragment { |
|
|
|
|
/** |
|
|
|
|
* The fragment argument representing the section number for this |
|
|
|
|
* fragment. |
|
|
|
|
*/ |
|
|
|
|
private static final String ARG_SECTION_NUMBER = "section_number"; |
|
|
|
|
|
|
|
|
|
private TextView textViewSolde; |
|
|
|
|
private TextView textViewUserName; |
|
|
|
|
private TextView textViewBirthday; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns a new instance of this fragment for the given section |
|
|
|
|
* number. |
|
|
|
|
*/ |
|
|
|
|
public static PlaceholderFragment newInstance(int sectionNumber) { |
|
|
|
|
PlaceholderFragment fragment = new PlaceholderFragment(); |
|
|
|
|
Bundle args = new Bundle(); |
|
|
|
|
args.putInt(ARG_SECTION_NUMBER, sectionNumber); |
|
|
|
|
fragment.setArguments(args); |
|
|
|
|
return fragment; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public PlaceholderFragment() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setInfos(List<String> infos) { |
|
|
|
|
|
|
|
|
|
// Show values
|
|
|
|
|
textViewSolde.setText(infos.get(0)); |
|
|
|
|
textViewSolde.invalidate(); |
|
|
|
|
textViewUserName.setText(infos.get(1)); |
|
|
|
|
textViewUserName.invalidate(); |
|
|
|
|
textViewBirthday.setText(infos.get(2)); |
|
|
|
|
textViewBirthday.invalidate(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, |
|
|
|
|
Bundle savedInstanceState) { |
|
|
|
|
View rootView = inflater.inflate(R.layout.fragment_main, container, false); |
|
|
|
|
|
|
|
|
|
textViewSolde = (TextView) rootView.findViewById(R.id.textViewSolde); |
|
|
|
|
textViewUserName = (TextView) rootView.findViewById(R.id.textViewUserName); |
|
|
|
|
textViewBirthday = (TextView) rootView.findViewById(R.id.textViewBirthday); |
|
|
|
|
|
|
|
|
|
return rootView; |
|
|
|
|
} |
|
|
|
|
// Store infos
|
|
|
|
|
solde = infos.get(0); |
|
|
|
|
username = infos.get(1); |
|
|
|
|
birthday = infos.get(2); |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onAttach(Activity activity) { |
|
|
|
|
super.onAttach(activity); |
|
|
|
|
((MainActivity) activity).onSectionAttached( |
|
|
|
|
getArguments().getInt(ARG_SECTION_NUMBER)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setInfos(List<String> infos) { |
|
|
|
|
saveUserData(); |
|
|
|
|
|
|
|
|
|
// Set infos to the fragment
|
|
|
|
|
mPlaceholderFrament.setInfos(infos); |
|
|
|
@ -258,17 +223,17 @@ public class MainActivity extends Activity
|
|
|
|
|
|
|
|
|
|
private void saveUserData() { |
|
|
|
|
|
|
|
|
|
editor.putString("solde", solde); |
|
|
|
|
editor.putString("username", username); |
|
|
|
|
editor.putString("birthday", birthday); |
|
|
|
|
editor.putString(SOLDE_KEY, solde); |
|
|
|
|
editor.putString(USERNAME_KEY, username); |
|
|
|
|
editor.putString(BIRTHDAY_KEY, birthday); |
|
|
|
|
editor.commit(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void quit() { |
|
|
|
|
new AlertDialog.Builder(this) |
|
|
|
|
.setMessage("Quitter ?") |
|
|
|
|
.setMessage(getString(R.string.question_quit)) |
|
|
|
|
.setCancelable(false) |
|
|
|
|
.setPositiveButton("Oui", new DialogInterface.OnClickListener() { |
|
|
|
|
.setPositiveButton(getString(R.string.action_yes), new DialogInterface.OnClickListener() { |
|
|
|
|
public void onClick(DialogInterface dialog, int id) { |
|
|
|
|
|
|
|
|
|
// Save user data
|
|
|
|
@ -278,7 +243,7 @@ public class MainActivity extends Activity
|
|
|
|
|
MainActivity.this.finish(); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.setNegativeButton("Non", new DialogInterface.OnClickListener() { |
|
|
|
|
.setNegativeButton(getString(R.string.action_no), new DialogInterface.OnClickListener() { |
|
|
|
|
public void onClick(DialogInterface dialog, int id) { |
|
|
|
|
dialog.dismiss(); |
|
|
|
|
} |
|
|
|
|