Skip to content

Commit

Permalink
Merge pull request #45 from zVolt/dev
Browse files Browse the repository at this point in the history
fix pin and addon card add UI
  • Loading branch information
zkhan93 authored Oct 3, 2022
2 parents e55b6a3 + 06ff19e commit 34db58d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 84 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 30
buildToolsVersion '30.0.2'
ndkVersion "22.1.7171670"

compileOptions {
Expand All @@ -19,7 +18,8 @@ android {
versionCode 14
versionName "1.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resConfigs "en" // FirebaseUI includes translations for all string resources.
resConfigs 'en'
// FirebaseUI includes translations for all string resources.
}
signingConfigs {
release {
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/io/github/zkhan93/familyfinance/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
Expand Down Expand Up @@ -61,6 +62,20 @@ public void setBiometricAuthValidFromTimeToNow() {
System.currentTimeMillis()).apply();
}

public void requestAuth(FragmentActivity activity){

if (BiometricManager.from(getApplicationContext())
.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) ==
BiometricManager.BIOMETRIC_SUCCESS) {
requestBiometricAuth(activity);
} else {
Toast.makeText(getApplicationContext(),
"Enable device PIN to use the app!", Toast.LENGTH_SHORT).show();
Log.d(TAG, "cannot use biometric of device login");
activity.finish();
}
}

public void requestBiometricAuth(FragmentActivity activity) {
long biometricAuthThreshold = 10 * 1000;
long lastAuthAt = spf.getLong(getString(R.string.pref_success_biometric_auth_at), 0);
Expand Down Expand Up @@ -107,7 +122,7 @@ public void onAuthenticationFailed() {
if (Build.VERSION.SDK_INT > 29) {
builder = builder.setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL);
}else{
builder = builder.setNegativeButtonText(getString(R.string.cancel));
builder.setDeviceCredentialAllowed(true);
}
promptInfo = builder.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
import android.view.ViewGroup;
import android.widget.TextView;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.ValueFormatter;

import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand All @@ -25,6 +16,7 @@

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;
Expand All @@ -34,6 +26,7 @@
import io.github.zkhan93.familyfinance.models.CCard;
import io.github.zkhan93.familyfinance.models.CCardDao;
import io.github.zkhan93.familyfinance.models.DaoSession;
import io.github.zkhan93.familyfinance.util.Util;
import io.github.zkhan93.familyfinance.vm.AppState;


Expand All @@ -58,7 +51,6 @@ public class FragmentCCardDetail extends Fragment {
TextView password;
TextView cardLimit;

LineChart chart;

private CCardDao cCardDao;
private AppState appState;
Expand All @@ -85,6 +77,7 @@ public void onCreate(Bundle savedInstanceState) {
if (getArguments() != null) {
card = getArguments().getParcelable(ARG_CARD);
}
appState = new ViewModelProvider(requireActivity()).get(AppState.class);
}

@Override
Expand All @@ -107,8 +100,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
password = rootView.findViewById(R.id.password);
cardLimit = rootView.findViewById(R.id.card_limit);

chart = rootView.findViewById(R.id.chart);

Bundle bundle = getArguments();
if (bundle != null) {
card = bundle.getParcelable("card");
Expand All @@ -118,70 +109,26 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
}
setCardDetails();
setUpCards();
setUpChart();
initFab();
return rootView;
}

private void setUpChart() {
List<Entry> entries = new ArrayList<>();
// turn your data into Entry objects
entries.add(new Entry(1, 1334));
entries.add(new Entry(2, 1543));
entries.add(new Entry(3, 3543));
entries.add(new Entry(4, 643));
entries.add(new Entry(5, 4632));

LineDataSet dataSet = new LineDataSet(entries, "Earning"); // add entries to dataset
dataSet.setDrawFilled(false);
dataSet.setValueTextSize(16);
dataSet.setDrawValues(true);
dataSet.setLineWidth(2f);
dataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
dataSet.setColor(getResources().getColor(R.color.md_green_500));
dataSet.setDrawCircles(false);


LineData lineData = new LineData();
lineData.addDataSet(dataSet);
Legend legend = chart.getLegend();
legend.setEnabled(false);

chart.setData(lineData);
chart.setDescription(null);
chart.setDrawGridBackground(false);
chart.setDrawBorders(false);
chart.setPinchZoom(false);
chart.setDoubleTapToZoomEnabled(false);
chart.setTouchEnabled(false);
chart.getXAxis().setSpaceMin(1);
chart.getXAxis().setSpaceMax(1);
chart.getXAxis().setDrawAxisLine(false);
chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
chart.getXAxis().setDrawGridLines(false);
chart.getXAxis().setValueFormatter(new ValueFormatter() {
@Override
public String getAxisLabel(float value, AxisBase axis) {
switch (String.valueOf(value)) {
case "1.0":
return "Jan";
case "2.0":
return "Feb";
case "3.0":
return "Mar";
case "4.0":
return "Apr";
case "5.0":
return "May";
}
return "";
@Override
public void onResume() {
super.onResume();
initFab();
}

private void initFab() {
appState.enableFab(R.drawable.ic_add_white_24dp, TAG);
appState.getFabAction().observe(getViewLifecycleOwner(), event -> {
String id = event.getContentIfNotHandled();
if (id != null && id.equals(TAG)){
Util.Log.d(TAG, "addon add click for: %s", id);
DialogFragmentAddonCard.newInstance(familyId, card.getNumber()).show(getParentFragmentManager(),
DialogFragmentCcard.TAG);
}
});
chart.getAxisLeft().setEnabled(false);
chart.getAxisRight().setEnabled(false);

chart.invalidate();
// dataSet.setColor();
// dataSet.setValueTextColor(...); // styling, ...
}

private void setUpCards() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ protected void onCreate(Bundle savedInstanceState) {
protected void onStart() {
super.onStart();
checkRequiredPermissions();
((App)getApplication()).requestBiometricAuth(this);
((App)getApplication()).requestAuth(this);
}

@Override
protected void onResume() {
super.onResume();
((App)getApplication()).requestBiometricAuth(this);
((App)getApplication()).requestAuth(this);
}

private void checkRequiredPermissions() {
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/layout/fragment_ccard_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,6 @@
android:visibility="gone"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/listitem_card_activity" />
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart"
android:layout_marginBottom="@dimen/large"
android:layout_width="match_parent"
android:layout_height="250dp" />
</LinearLayout>

</LinearLayout>
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.2.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.3.8'
classpath 'com.google.gms:google-services:4.3.10'
classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0'

}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip

0 comments on commit 34db58d

Please sign in to comment.