New features

- App loading animation generated from cached icons
- Import backups (data format will be reworked)
- Fix cryptocompare crash because of an API update
This commit is contained in:
Tanguy Herbron 2018-07-15 00:32:51 +02:00
parent e173e48612
commit 7946ba4897
11 changed files with 275 additions and 34 deletions

Binary file not shown.

19
.idea/statistic.xml generated Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Statistic">
<option name="fileTypes" value="class;svn-base;svn-work;Extra;gif;png;jpg;jpeg;bmp;tga;tiff;ear;war;zip;jar;iml;iws;ipr;bz2;gz;ap;apk;bin;dex;flat;gitignore;gson;json;md;pro;store;ttf;txt;ap_;" />
<option name="excludedDirectories">
<list>
<option value="$PROJECT_DIR$/.idea" />
<option value="$PROJECT_DIR$/.gradle" />
<option value="$PROJECT_DIR$/export" />
<option value="$PROJECT_DIR$/gource" />
<option value="$PROJECT_DIR$/gradle" />
<option value="$PROJECT_DIR$/libs" />
<option value="$PROJECT_DIR$/app/src/test" />
<option value="$PROJECT_DIR$/app/src/androidTest" />
<option value="$PROJECT_DIR$/app/build" />
</list>
</option>
</component>
</project>

View File

@ -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'

View File

@ -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();
}

View File

@ -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");

View File

@ -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<>();

View File

@ -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<Currency> getAllCurrenciesFromWatchlist()
{
String searchQuerry = "SELECT * FROM " + TABLE_WATCHLIST + " ORDER BY " + KEY_WATCHLIST_POSITION + " ASC";

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:theme="@style/AppTheme"
android:padding="5dp"
android:focusableInTouchMode="true">
<TextView
android:id="@+id/textViewFilePath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Click to select"
android:background="@drawable/background_filepath"/>
<CheckBox
android:id="@+id/checkboxConserveData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/conserve_data"
android:enabled="false" />
<CheckBox
android:id="@+id/checkboxRestoreEntries"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/restore_manual_entries"
android:enabled="false" />
<CheckBox
android:id="@+id/checkboxRestoreKeys"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/restore_keys"
android:enabled="false" />
<CheckBox
android:id="@+id/checkboxEnterPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/enter_password"
android:enabled="false"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>

View File

@ -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"/>
<CheckBox
android:id="@+id/checkboxRestoreEntries"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/restore_manual_entries" />
android:text="@string/restore_manual_entries"
android:enabled="false" />
<CheckBox
android:id="@+id/checkboxRestoreKeys"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/restore_keys" />
android:text="@string/restore_keys"
android:enabled="false" />
<CheckBox
android:id="@+id/checkboxEnterPassword"

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/colorPrimaryDark">
<LinearLayout
android:id="@+id/animatedViewsLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
</LinearLayout>
</LinearLayout>

View File

@ -31,8 +31,7 @@
android:key="export"/>
<Preference android:title="@string/pref_title_import"
android:key="import"
android:enabled="false"/>
android:key="import"/>
</PreferenceCategory>