diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 517e430..af2e6fc 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/statistic.xml b/.idea/statistic.xml new file mode 100644 index 0000000..18e053b --- /dev/null +++ b/.idea/statistic.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d5a242c..5bd87b3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,6 +53,7 @@ dependencies { implementation 'com.wdullaer:materialdatetimepicker:3.5.2' implementation 'com.jmedeisis:draglinearlayout:1.1.0' implementation 'com.applandeo:material-file-picker:1.0.0' + implementation 'com.daasuu:EasingInterpolator:1.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' diff --git a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java index b684869..19aa676 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/herbron/moodl/Activities/HomeActivityFragments/Summary.java @@ -1,10 +1,14 @@ package com.herbron.moodl.Activities.HomeActivityFragments; +import android.animation.ObjectAnimator; +import android.animation.ValueAnimator; import android.app.Dialog; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Paint; import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; @@ -13,6 +17,7 @@ import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.Snackbar; import android.support.v4.app.Fragment; import android.os.Bundle; +import android.support.v4.content.ContextCompat; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; @@ -24,10 +29,13 @@ import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; +import com.daasuu.ei.Ease; +import com.daasuu.ei.EasingInterpolator; import com.herbron.moodl.Activities.CurrencySelectionActivity; import com.herbron.moodl.Activities.HomeActivity; import com.herbron.moodl.BalanceUpdateInterface; @@ -42,8 +50,10 @@ import com.herbron.moodl.MoodlBox; import com.herbron.moodl.PlaceholderManager; import com.herbron.moodl.R; +import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Random; import static com.herbron.moodl.MoodlBox.getColor; import static com.herbron.moodl.MoodlBox.numberConformer; @@ -238,28 +248,48 @@ public class Summary extends Fragment implements BalanceSwitchManagerInterface, private void generateSplashScreen() { - LinearLayout loadingLayout = new LinearLayout(getActivity()); - - loadingLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - loadingLayout.setGravity(Gravity.CENTER); - loadingLayout.setOrientation(LinearLayout.VERTICAL); - loadingDialog = new Dialog(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen); - TextView txtView = new TextView(getActivity()); - txtView.setText("Loading data..."); - txtView.setTextSize(20); - txtView.setGravity(Gravity.CENTER); - txtView.setTextColor(this.getResources().getColor(R.color.cardview_light_background)); + Random random = new Random(); - ProgressBar progressBar = new ProgressBar(getActivity()); - progressBar.setIndeterminate(true); + LinearLayout splashLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.splash_screen, null, true); + LinearLayout animatedLayout = splashLayout.findViewById(R.id.animatedViewsLayout); - loadingLayout.setBackgroundColor(getActivity().getResources().getColor(R.color.colorPrimaryDark)); - loadingLayout.addView(txtView); - loadingLayout.addView(progressBar); + File cacheDir = new File(getContext().getCacheDir().getAbsolutePath()); + File[] cacheFiles = cacheDir.listFiles(); - loadingDialog.setContentView(loadingLayout); + for(int i = 0; i < 4; i++) + { + File cachedIcon = null; + + while(cachedIcon == null || cachedIcon.isDirectory()) + { + cachedIcon = cacheFiles[random.nextInt(cacheFiles.length) + 1]; + } + + Bitmap icon = BitmapFactory.decodeFile(cachedIcon.getAbsolutePath()); + + Bitmap result = Bitmap.createBitmap(150, 150, icon.getConfig()); + + Paint paint = new Paint(); + paint.setStyle(Paint.Style.FILL); + paint.setColor(ContextCompat.getColor(getContext(), R.color.white)); + + Canvas canvas = new Canvas(result); + canvas.drawCircle(result.getHeight()/2, result.getWidth()/2, 75, paint); + canvas.drawBitmap(Bitmap.createScaledBitmap(icon, 100, 100, false), result.getHeight()/2 - 50, result.getWidth()/2 - 50, null); + + ((ImageView) animatedLayout.getChildAt(i)).setImageBitmap(result); + + ObjectAnimator animator = ObjectAnimator.ofFloat(animatedLayout.getChildAt(i), "translationY", 0, -100, 0); + animator.setInterpolator(new EasingInterpolator(Ease.CIRC_IN_OUT)); + animator.setStartDelay(i*200); + animator.setDuration(1500); + animator.setRepeatCount(ValueAnimator.INFINITE); + animator.start(); + } + + loadingDialog.setContentView(splashLayout); loadingDialog.show(); } diff --git a/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java b/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java index d83e2c2..c3a342d 100644 --- a/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java +++ b/app/src/main/java/com/herbron/moodl/Activities/SettingsActivity.java @@ -3,11 +3,9 @@ package com.herbron.moodl.Activities; import android.Manifest; import android.annotation.TargetApi; import android.app.AlertDialog; -import android.app.Dialog; import android.app.KeyguardManager; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; @@ -29,22 +27,15 @@ import android.support.design.widget.TextInputLayout; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; -import android.support.v7.view.ContextThemeWrapper; import android.util.Log; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.CompoundButton; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.ProgressBar; import android.widget.TextView; import com.applandeo.FilePicker; -import com.applandeo.constants.FileType; import com.applandeo.listeners.OnSelectFileListener; import com.herbron.moodl.BuildConfig; import com.herbron.moodl.DataManagers.DataCrypter; @@ -181,7 +172,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { Context context = SettingsActivity.this; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context); - View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_import_data, null, true); + 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)); @@ -202,7 +193,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { public void onSelect(File file) { textViewFilePath.setText(file.getAbsolutePath()); } - }).fileType("moodl") + }).fileType(".moodl") .hideFiles(true) .directory(backupDirectory.getAbsolutePath()) .mainDirectory(Environment.getExternalStorageDirectory().getAbsolutePath()) @@ -273,6 +264,93 @@ public class SettingsActivity extends AppCompatPreferenceActivity { } }); + 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"); diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java index 0978aac..e17a047 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/CurrencyData/CurrencyDetailsList.java @@ -77,7 +77,7 @@ public class CurrencyDetailsList { private void processDetailResult(String response, final BalanceManager.IconCallBack callBack) { - response = response.substring(response.indexOf("\"Data\"") + 7, response.lastIndexOf("},\"Type\":100}")); + response = response.substring(response.indexOf("\"Data\"") + 7, response.lastIndexOf("},\"BaseImageUrl\"")); String[] tab = response.split(Pattern.quote("},")); coinInfosHashmap = new LinkedHashMap<>(); diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java index c01d8cb..bb9635d 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DatabaseManager.java @@ -173,6 +173,20 @@ public class DatabaseManager extends SQLiteOpenHelper{ return backupData; } + public void addRowTransaction(String[] rowValues) + { + SQLiteDatabase db = this.getWritableDatabase(); + ContentValues values = new ContentValues(); + + values.put(KEY_CURRENCY_SYMBOL, rowValues[1]); + values.put(KEY_CURRENCY_BALANCE, rowValues[3]); + values.put(KEY_CURRENCY_DATE, rowValues[4]); + values.put(KEY_CURRENCY_PURCHASED_PRICE, rowValues[5]); + + db.insert(TABLE_MANUAL_CURRENCIES, null, values); + db.close(); + } + public List getAllCurrenciesFromWatchlist() { String searchQuerry = "SELECT * FROM " + TABLE_WATCHLIST + " ORDER BY " + KEY_WATCHLIST_POSITION + " ASC"; diff --git a/app/src/main/res/layout/dialog_export_data.xml b/app/src/main/res/layout/dialog_export_data.xml new file mode 100644 index 0000000..962baaf --- /dev/null +++ b/app/src/main/res/layout/dialog_export_data.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_import_data.xml b/app/src/main/res/layout/dialog_import_data.xml index f835b49..169bf82 100644 --- a/app/src/main/res/layout/dialog_import_data.xml +++ b/app/src/main/res/layout/dialog_import_data.xml @@ -20,19 +20,22 @@ android:id="@+id/checkboxConserveData" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/conserve_data" /> + android:text="@string/conserve_data" + android:enabled="false"/> + android:text="@string/restore_manual_entries" + android:enabled="false" /> + android:text="@string/restore_keys" + android:enabled="false" /> + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/xml/pref_main.xml index aba5341..75adcd9 100644 --- a/app/src/main/res/xml/pref_main.xml +++ b/app/src/main/res/xml/pref_main.xml @@ -31,8 +31,7 @@ android:key="export"/> + android:key="import"/>