Bug fixes

- Rework SettingsActivity code to make it clearer
- Fix crash when loading app icon as default icon
This commit is contained in:
Tanguy Herbron 2018-07-15 21:20:26 +02:00
parent 7946ba4897
commit 2b165ba2a0
13 changed files with 418 additions and 279 deletions

46
.idea/assetWizardSettings.xml generated Normal file
View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WizardSettings">
<option name="children">
<map>
<entry key="vectorWizard">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="vectorAssetStep">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="clipartAsset">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="url" value="jar:file:/C:/Program%20Files/Android/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/image/ic_panorama_fish_eye_black_24dp.xml" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
<option name="values">
<map>
<entry key="outputName" value="ic_panorama_fish_eye_24dp" />
<entry key="sourceFile" value="C:\Users\Guitoune" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</component>
</project>

Binary file not shown.

View File

@ -9,6 +9,7 @@ android {
versionCode 6 versionCode 6
versionName "0.0.6" versionName "0.0.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
} }
dataBinding { dataBinding {
@ -54,6 +55,7 @@ dependencies {
implementation 'com.jmedeisis:draglinearlayout:1.1.0' implementation 'com.jmedeisis:draglinearlayout:1.1.0'
implementation 'com.applandeo:material-file-picker:1.0.0' implementation 'com.applandeo:material-file-picker:1.0.0'
implementation 'com.daasuu:EasingInterpolator:1.0.0' implementation 'com.daasuu:EasingInterpolator:1.0.0'
implementation 'com.android.support:support-vector-drawable:27.1.1'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

View File

@ -2,7 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.herbron.moodl"> package="com.herbron.moodl">
<uses-feature android:name="android.hardware.fingerprint" <uses-feature
android:name="android.hardware.fingerprint"
android:required="false" /> android:required="false" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
@ -17,11 +18,11 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity <activity
android:name="com.herbron.moodl.Activities.HomeActivity" android:name=".Activities.HomeActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" android:theme="@style/AppTheme.NoActionBar">
android:launchMode="singleTop">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -29,25 +30,25 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name="com.herbron.moodl.Activities.SettingsActivity" android:name=".Activities.SettingsActivity"
android:label="@string/title_activity_settings" android:label="@string/title_activity_settings"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity <activity
android:name="com.herbron.moodl.Activities.CurrencySelectionActivity" android:name=".Activities.CurrencySelectionActivity"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value="com.herbron.moodl.Activities.HomeActivity" /> android:value="com.herbron.moodl.Activities.HomeActivity" />
</activity> </activity>
<activity <activity
android:name="com.herbron.moodl.Activities.RecordTransactionActivity" android:name=".Activities.RecordTransactionActivity"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<meta-data <meta-data
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value="com.herbron.moodl.Activities.HomeActivity" /> android:value="com.herbron.moodl.Activities.HomeActivity" />
</activity> </activity>
<activity <activity
android:name="com.herbron.moodl.Activities.CurrencyDetailsActivity" android:name=".Activities.CurrencyDetailsActivity"
android:label="@string/title_activity_currency_details" android:label="@string/title_activity_currency_details"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<meta-data <meta-data

View File

@ -3,6 +3,7 @@ package com.herbron.moodl.Activities;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
@ -98,6 +99,8 @@ public class HomeActivity extends AppCompatActivity implements BalanceUpdateInte
break; break;
case R.id.navigation_settings: case R.id.navigation_settings:
Intent settingIntent = new Intent(getApplicationContext(), SettingsActivity.class); Intent settingIntent = new Intent(getApplicationContext(), SettingsActivity.class);
settingIntent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.MainPreferenceFragment.class.getName() );
settingIntent.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true );
startActivity(settingIntent); startActivity(settingIntent);
item.setChecked(false); item.setChecked(false);
break; break;

View File

@ -2,6 +2,8 @@ package com.herbron.moodl.Activities.HomeActivityFragments;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
@ -27,6 +29,8 @@ import com.herbron.moodl.R;
import java.util.List; import java.util.List;
import static com.herbron.moodl.MoodlBox.getDrawable;
/** /**
* Created by Administrator on 27/05/2018. * Created by Administrator on 27/05/2018.
*/ */
@ -185,7 +189,14 @@ public class Overview extends Fragment {
} }
else else
{ {
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl); Drawable drawable = getDrawable(R.drawable.ic_panorama_fish_eye_24dp, getContext());
Bitmap icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(icon);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
icon = Bitmap.createScaledBitmap(icon, 50, 50, false); icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
currency.setIcon(icon); currency.setIcon(icon);

View File

@ -9,6 +9,8 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -56,6 +58,7 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import static com.herbron.moodl.MoodlBox.getColor; import static com.herbron.moodl.MoodlBox.getColor;
import static com.herbron.moodl.MoodlBox.getDrawable;
import static com.herbron.moodl.MoodlBox.numberConformer; import static com.herbron.moodl.MoodlBox.numberConformer;
import static java.lang.Math.abs; import static java.lang.Math.abs;
@ -264,7 +267,7 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
while(cachedIcon == null || cachedIcon.isDirectory()) while(cachedIcon == null || cachedIcon.isDirectory())
{ {
cachedIcon = cacheFiles[random.nextInt(cacheFiles.length) + 1]; cachedIcon = cacheFiles[random.nextInt(cacheFiles.length)];
} }
Bitmap icon = BitmapFactory.decodeFile(cachedIcon.getAbsolutePath()); Bitmap icon = BitmapFactory.decodeFile(cachedIcon.getAbsolutePath());
@ -766,7 +769,14 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface,
} }
else else
{ {
Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_moodl); Drawable drawable = getDrawable(R.drawable.ic_panorama_fish_eye_24dp, getContext());
Bitmap icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(icon);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
icon = Bitmap.createScaledBitmap(icon, 50, 50, false); icon = Bitmap.createScaledBitmap(icon, 50, 50, false);
localCurrency.setIcon(icon); localCurrency.setIcon(icon);

View File

@ -6,6 +6,7 @@ import android.app.AlertDialog;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -159,223 +160,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setupActionBar(); setupActionBar();
addPreferencesFromResource(R.xml.pref_main);
findPreference("version").setSummary(BuildConfig.VERSION_NAME);
bindPreferenceSummaryToValue(findPreference("default_currency"));
bindPreferenceSummaryToValue(findPreference("minimum_value_displayed"));
findPreference("export").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Context context = SettingsActivity.this;
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_export_data, null, true);
dialogBuilder.setView(dialogView);
File backupDirectory = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name));
if (!backupDirectory.exists()) {
if (!backupDirectory.mkdirs()) {
Log.d("moodl", "Error while creating directory");
}
}
final TextView textViewFilePath = dialogView.findViewById(R.id.textViewFilePath);
textViewFilePath.setText(backupDirectory.getAbsolutePath());
textViewFilePath.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new FilePicker.Builder(SettingsActivity.this, new OnSelectFileListener() {
@Override
public void onSelect(File file) {
textViewFilePath.setText(file.getAbsolutePath());
}
}).fileType(".moodl")
.hideFiles(true)
.directory(backupDirectory.getAbsolutePath())
.mainDirectory(Environment.getExternalStorageDirectory().getAbsolutePath())
.show();
}
});
final CheckBox enterPasswordCheckbox = dialogView.findViewById(R.id.checkboxEnterPassword);
final TextInputLayout textInputLayoutPassword = dialogView.findViewById(R.id.textInputLayoutPassword);
enterPasswordCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b && textInputLayoutPassword.getVisibility() == View.GONE)
{
MoodlBox.expandH(textInputLayoutPassword);
}
if(!b && textInputLayoutPassword.getVisibility() == View.VISIBLE)
{
MoodlBox.collapseH(textInputLayoutPassword);
}
}
});
dialogBuilder.setTitle("Create backup");
dialogBuilder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
checkPermissions();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.getDefault());
Date currentDate = new Date();
String fileName = getString(R.string.app_name) + "_" + formatter.format(currentDate) + ".backup";
DatabaseManager databaseManager = new DatabaseManager(SettingsActivity.this);
File backupFile = new File(textViewFilePath.getText() + "/" + fileName);
try (PrintWriter printWriter = new PrintWriter(new FileWriter(backupFile, true))) {
if(enterPasswordCheckbox.isChecked())
{
DataCrypter.updateKey(textInputLayoutPassword.getEditText().getText().toString());
printWriter.write(DataCrypter.encrypt(SettingsActivity.this, databaseManager.getBackupData()));
}
else
{
printWriter.write(databaseManager.getBackupData());
}
printWriter.close();
} catch (IOException e) {
Log.d("moodl", "Error > " + e);
}
dialog.dismiss();
}
});
dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
return false;
}
});
findPreference("import").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Context context = SettingsActivity.this;
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_import_data, null, true);
dialogBuilder.setView(dialogView);
File backupDirectory = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name));
if(!backupDirectory.exists())
{
if(!backupDirectory.mkdirs())
{
Log.d("moodl", "Error while creating directory");
}
}
final TextView textViewFilePath = dialogView.findViewById(R.id.textViewFilePath);
textViewFilePath.setText(backupDirectory.getAbsolutePath());
textViewFilePath.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new FilePicker.Builder(SettingsActivity.this, new OnSelectFileListener() {
@Override
public void onSelect(File file) {
textViewFilePath.setText(file.getAbsolutePath());
}
}).hideFiles(false)
.directory(backupDirectory.getAbsolutePath())
.mainDirectory(Environment.getExternalStorageDirectory().getAbsolutePath())
.show();
}
});
dialogBuilder.setTitle("Restore backup");
dialogBuilder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int whichButton) {
checkPermissions();
DatabaseManager databaseManager = new DatabaseManager(context);
File backupFile = new File(textViewFilePath.getText().toString());
try {
FileReader fileReader = new FileReader(backupFile);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String str;
String completeFile = "";
while ((str = bufferedReader.readLine()) != null) {
completeFile += str;
}
String[] results = completeFile.split(Pattern.quote("]"));
for(int i = 0; i < results.length; i++)
{
String[] columnValues = results[i].split(Pattern.quote(";@"));
databaseManager.addRowTransaction(columnValues);
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
return false;
}
});
EditTextPreference editTextPreference = (EditTextPreference) findPreference("minimum_value_displayed");
editTextPreference.setPositiveButtonText("Save");
editTextPreference.setNegativeButtonText("Cancel");
}
private boolean checkPermissions() {
String[] permissions = new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
};
int result;
List<String> listPermissionsNeeded = new ArrayList<>();
for (String p : permissions) {
result = ContextCompat.checkSelfPermission(this, p);
if (result != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(p);
}
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), 100);
return false;
}
return true;
} }
/** /**
@ -412,7 +196,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
*/ */
protected boolean isValidFragment(String fragmentName) { protected boolean isValidFragment(String fragmentName) {
return PreferenceFragment.class.getName().equals(fragmentName) return PreferenceFragment.class.getName().equals(fragmentName)
|| ExchangePreferenceFragment.class.getName().equals(fragmentName); || ExchangePreferenceFragment.class.getName().equals(fragmentName)
|| MainPreferenceFragment.class.getName().equals(fragmentName);
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@ -439,6 +224,14 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
bindPreferenceSummaryToValue(findPreference("hitbtc_privatekey")); bindPreferenceSummaryToValue(findPreference("hitbtc_privatekey"));
bindPreferenceSummaryToValue(findPreference("binance_privatekey")); bindPreferenceSummaryToValue(findPreference("binance_privatekey"));
findPreference("enable_fingerprint").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
return false;
}
});
findPreference("enable_hitbtc").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { findPreference("enable_hitbtc").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
@ -600,4 +393,243 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
} }
} }
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class MainPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_main);
findPreference("version").setSummary(BuildConfig.VERSION_NAME);
bindPreferenceSummaryToValue(findPreference("default_currency"));
bindPreferenceSummaryToValue(findPreference("minimum_value_displayed"));
findPreference("export").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Context context = getContext();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_export_data, null, true);
dialogBuilder.setView(dialogView);
File backupDirectory = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name));
if (!backupDirectory.exists()) {
if (!backupDirectory.mkdirs()) {
Log.d("moodl", "Error while creating directory");
}
}
final TextView textViewFilePath = dialogView.findViewById(R.id.textViewFilePath);
textViewFilePath.setText(backupDirectory.getAbsolutePath());
textViewFilePath.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new FilePicker.Builder(getActivity(), new OnSelectFileListener() {
@Override
public void onSelect(File file) {
textViewFilePath.setText(file.getAbsolutePath());
}
}).fileType(".moodl")
.hideFiles(true)
.directory(backupDirectory.getAbsolutePath())
.mainDirectory(Environment.getExternalStorageDirectory().getAbsolutePath())
.show();
}
});
final CheckBox enterPasswordCheckbox = dialogView.findViewById(R.id.checkboxEnterPassword);
final TextInputLayout textInputLayoutPassword = dialogView.findViewById(R.id.textInputLayoutPassword);
enterPasswordCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b && textInputLayoutPassword.getVisibility() == View.GONE)
{
MoodlBox.expandH(textInputLayoutPassword);
}
if(!b && textInputLayoutPassword.getVisibility() == View.VISIBLE)
{
MoodlBox.collapseH(textInputLayoutPassword);
}
}
});
dialogBuilder.setTitle("Create backup");
dialogBuilder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
checkPermissions();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.getDefault());
Date currentDate = new Date();
String fileName = getString(R.string.app_name) + "_" + formatter.format(currentDate) + ".backup";
DatabaseManager databaseManager = new DatabaseManager(getContext());
File backupFile = new File(textViewFilePath.getText() + "/" + fileName);
try (PrintWriter printWriter = new PrintWriter(new FileWriter(backupFile, true))) {
if(enterPasswordCheckbox.isChecked())
{
DataCrypter.updateKey(textInputLayoutPassword.getEditText().getText().toString());
printWriter.write(DataCrypter.encrypt(getActivity(), databaseManager.getBackupData()));
}
else
{
printWriter.write(databaseManager.getBackupData());
}
printWriter.close();
} catch (IOException e) {
Log.d("moodl", "Error > " + e);
}
dialog.dismiss();
}
});
dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
return false;
}
});
findPreference("import").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Context context = getContext();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_import_data, null, true);
dialogBuilder.setView(dialogView);
File backupDirectory = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name));
if(!backupDirectory.exists())
{
if(!backupDirectory.mkdirs())
{
Log.d("moodl", "Error while creating directory");
}
}
final TextView textViewFilePath = dialogView.findViewById(R.id.textViewFilePath);
textViewFilePath.setText(backupDirectory.getAbsolutePath());
textViewFilePath.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new FilePicker.Builder(getActivity(), new OnSelectFileListener() {
@Override
public void onSelect(File file) {
textViewFilePath.setText(file.getAbsolutePath());
}
}).hideFiles(false)
.directory(backupDirectory.getAbsolutePath())
.mainDirectory(Environment.getExternalStorageDirectory().getAbsolutePath())
.show();
}
});
dialogBuilder.setTitle("Restore backup");
dialogBuilder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int whichButton) {
checkPermissions();
DatabaseManager databaseManager = new DatabaseManager(context);
File backupFile = new File(textViewFilePath.getText().toString());
try {
FileReader fileReader = new FileReader(backupFile);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String str;
String completeFile = "";
while ((str = bufferedReader.readLine()) != null) {
completeFile += str;
}
String[] results = completeFile.split(Pattern.quote("]"));
for(int i = 0; i < results.length; i++)
{
String[] columnValues = results[i].split(Pattern.quote(";@"));
databaseManager.addRowTransaction(columnValues);
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
return false;
}
});
EditTextPreference editTextPreference = (EditTextPreference) findPreference("minimum_value_displayed");
editTextPreference.setPositiveButtonText("Save");
editTextPreference.setNegativeButtonText("Cancel");
}
private boolean checkPermissions() {
String[] permissions = new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
};
int result;
List<String> listPermissionsNeeded = new ArrayList<>();
for (String p : permissions) {
result = ContextCompat.checkSelfPermission(getContext(), p);
if (result != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(p);
}
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(getActivity(), listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), 100);
return false;
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
//startActivity(new Intent(getActivity(), SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}
} }

View File

@ -35,7 +35,8 @@ public class FingerprintDialogFragment extends DialogFragment{
@Override @Override
public void onClick(View view) { public void onClick(View view) {
dismiss(); dismiss();
getActivity().finish(); getActivity().getFragmentManager().popBackStack();
//getActivity().finish();
} }
}); });

View File

@ -1,44 +0,0 @@
package com.herbron.moodl;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import com.herbron.moodl.Activities.HomeActivityFragments.MarketCapitalization;
import com.herbron.moodl.Activities.HomeActivityFragments.Summary;
import com.herbron.moodl.Activities.HomeActivityFragments.Watchlist;
/**
* Created by Tiji on 13/04/2018.
*/
public class HomeActivityPagerAdapter extends FragmentStatePagerAdapter {
private int numOfTabs;
public HomeActivityPagerAdapter(FragmentManager fm, int numOfTabs)
{
super(fm);
this.numOfTabs = numOfTabs;
}
@Override
public Fragment getItem(int position) {
switch (position)
{
case 0:
return new Watchlist();
case 1:
return new Summary();
case 2:
return new MarketCapitalization();
default:
return null;
}
}
@Override
public int getCount() {
return numOfTabs;
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/colorPrimary"
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
</vector>

View File

@ -207,5 +207,73 @@
<string name="restore_keys">Restore API keys</string> <string name="restore_keys">Restore API keys</string>
<string name="enter_password">Enter password</string> <string name="enter_password">Enter password</string>
<string name="password">Password</string> <string name="password">Password</string>
<string name="title_activity_exchange_settings">Settings</string>
<string name="pref_title_social_recommendations">Enable social recommendations</string>
<string name="pref_description_social_recommendations">Recommendations for people to contact
based on your message history
</string>
<string name="pref_title_display_name">Display name</string>
<string name="pref_default_display_name">John Smith</string>
<string name="pref_title_add_friends_to_messages">Add friends to messages</string>
<string-array name="pref_example_list_titles">
<item>Always</item>
<item>When possible</item>
<item>Never</item>
</string-array>
<string-array name="pref_example_list_values">
<item>1</item>
<item>0</item>
<item>-1</item>
</string-array>
<!-- Example settings for Data & Sync -->
<string name="pref_header_data_sync">Data &amp; sync</string>
<string name="pref_title_sync_frequency">Sync frequency</string>
<string-array name="pref_sync_frequency_titles">
<item>15 minutes</item>
<item>30 minutes</item>
<item>1 hour</item>
<item>3 hours</item>
<item>6 hours</item>
<item>Never</item>
</string-array>
<string-array name="pref_sync_frequency_values">
<item>15</item>
<item>30</item>
<item>60</item>
<item>180</item>
<item>360</item>
<item>-1</item>
</string-array>
<string-array name="list_preference_entries">
<item>Entry 1</item>
<item>Entry 2</item>
<item>Entry 3</item>
</string-array>
<string-array name="list_preference_entry_values">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="multi_select_list_preference_default_value" />
<string name="pref_title_system_sync_settings">System sync settings</string>
<!-- Example settings for Notifications -->
<string name="pref_header_notifications">Notifications</string>
<string name="pref_title_new_message_notifications">New message notifications</string>
<string name="pref_title_ringtone">Ringtone</string>
<string name="pref_ringtone_silent">Silent</string>
<string name="pref_title_vibrate">Vibrate</string>
</resources> </resources>

View File

@ -41,7 +41,7 @@
<PreferenceScreen <PreferenceScreen
android:fragment="com.herbron.moodl.Activities.SettingsActivity$ExchangePreferenceFragment" android:fragment="com.herbron.moodl.Activities.SettingsActivity$ExchangePreferenceFragment"
android:title="@string/pref_header_exchange" android:title="@string/pref_header_exchange"
android:enabled="false"/> android:key="exchange"/>
<PreferenceScreen <PreferenceScreen
android:title="@string/pref_header_wallet" android:title="@string/pref_header_wallet"