manage future dates entry option in the profile editor
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 17 Dec 2019 19:27:11 +0000 (21:27 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 17 Dec 2019 19:27:11 +0000 (21:27 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
app/src/main/res/layout/profile_detail.xml
app/src/main/res/menu/future_dates.xml [new file with mode: 0644]

index 3560831..4c54748 100644 (file)
@@ -29,6 +29,7 @@ import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
+import android.widget.PopupMenu;
 import android.widget.Switch;
 import android.widget.TextView;
 
@@ -92,6 +93,9 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
     private TextInputLayout preferredAccountsFilterLayout;
     private View huePickerView;
     private View insecureWarningText;
+    private TextView futureDatesText;
+    private MobileLedgerProfile.FutureDates futureDates;
+    private View futureDatesLayout;
 
     /**
      * Mandatory empty constructor for the fragment manager to instantiate the
@@ -224,6 +228,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
         mProfile.setAuthUserName(userName.getText());
         mProfile.setAuthPassword(password.getText());
         mProfile.setThemeId(huePickerView.getTag());
+        mProfile.setFutureDates(futureDates);
     }
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
@@ -235,6 +240,41 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
         url = rootView.findViewById(R.id.url);
         urlLayout = rootView.findViewById(R.id.url_layout);
         postingPermitted = rootView.findViewById(R.id.profile_permit_posting);
+        futureDatesLayout = rootView.findViewById(R.id.future_dates_layout);
+        futureDatesText = rootView.findViewById(R.id.future_dates_text);
+        rootView.findViewById(R.id.future_dates_layout)
+                .setOnClickListener(v -> {
+                    MenuInflater mi = new MenuInflater(getContext());
+                    PopupMenu menu = new PopupMenu(getContext(), v);
+                    menu.inflate(R.menu.future_dates);
+                    menu.setOnMenuItemClickListener(item -> {
+                        switch (item.getItemId()) {
+                            case R.id.menu_future_dates_30:
+                                futureDates = MobileLedgerProfile.FutureDates.OneMonth;
+                                break;
+                            case R.id.menu_future_dates_60:
+                                futureDates = MobileLedgerProfile.FutureDates.TwoMonths;
+                                break;
+                            case R.id.menu_future_dates_90:
+                                futureDates = MobileLedgerProfile.FutureDates.ThreeMonths;
+                                break;
+                            case R.id.menu_future_dates_180:
+                                futureDates = MobileLedgerProfile.FutureDates.SixMonths;
+                                break;
+                            case R.id.menu_future_dates_365:
+                                futureDates = MobileLedgerProfile.FutureDates.OneYear;
+                                break;
+                            case R.id.menu_future_dates_all:
+                                futureDates = MobileLedgerProfile.FutureDates.All;
+                                break;
+                            default:
+                                futureDates = MobileLedgerProfile.FutureDates.None;
+                        }
+                        futureDatesText.setText(futureDates.getText(getResources()));
+                        return true;
+                    });
+                    menu.show();
+                });
         authParams = rootView.findViewById(R.id.auth_params);
         useAuthentication = rootView.findViewById(R.id.enable_http_auth);
         userName = rootView.findViewById(R.id.auth_user_name);
@@ -254,9 +294,10 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
             checkInsecureSchemeWithAuth();
         });
 
-        postingPermitted.setOnCheckedChangeListener(
-                ((buttonView, isChecked) -> preferredAccountsFilterLayout
-                        .setVisibility(isChecked ? View.VISIBLE : View.GONE)));
+        postingPermitted.setOnCheckedChangeListener(((buttonView, isChecked) -> {
+            preferredAccountsFilterLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
+            futureDatesLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
+        }));
 
         hookClearErrorOnFocusListener(profileName, profileNameLayout);
         hookClearErrorOnFocusListener(url, urlLayout);
@@ -267,6 +308,8 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
         if (mProfile != null) {
             profileName.setText(mProfile.getName());
             postingPermitted.setChecked(mProfile.isPostingPermitted());
+            futureDates = mProfile.getFutureDates();
+            futureDatesText.setText(futureDates.getText(getResources()));
             url.setText(mProfile.getUrl());
             useAuthentication.setChecked(mProfile.isAuthEnabled());
             authParams.setVisibility(mProfile.isAuthEnabled() ? View.VISIBLE : View.GONE);
@@ -279,6 +322,8 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
             profileName.setText("");
             url.setText(HTTPS_URL_START);
             postingPermitted.setChecked(true);
+            futureDates = MobileLedgerProfile.FutureDates.None;
+            futureDatesText.setText(futureDates.getText(getResources()));
             useAuthentication.setChecked(false);
             authParams.setVisibility(View.GONE);
             userName.setText("");
index 49068d4..6a0d9ca 100644 (file)
             android:layout_marginBottom="16dp"
             android:text="@string/posting_permitted" />
 
+        <LinearLayout
+            android:id="@+id/future_dates_layout"
+            android:layout_width="match_parent"
+            android:layout_marginBottom="16dp"
+            android:layout_height="wrap_content"
+            android:orientation="vertical">
+
+            <TextView
+                android:id="@+id/future_dates_title"
+                android:textAppearance="?android:textAppearanceListItem"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:text="@string/profile_future_dates_label" />
+
+            <TextView
+                android:id="@+id/future_dates_text"
+                android:textAppearance="?android:textAppearanceListItemSecondary"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:textColor="?attr/textColor"/>
+        </LinearLayout>
+
         <Switch
             android:id="@+id/enable_http_auth"
             android:layout_width="match_parent"
diff --git a/app/src/main/res/menu/future_dates.xml b/app/src/main/res/menu/future_dates.xml
new file mode 100644 (file)
index 0000000..b318395
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright © 2019 Damyan Ivanov.
+  ~ This file is part of MoLe.
+  ~ MoLe is free software: you can distribute it and/or modify it
+  ~ under the term of the GNU General Public License as published by
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~ (at your opinion), any later version.
+  ~
+  ~ MoLe is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  ~ GNU General Public License terms for details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+  -->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:title="@string/future_dates_none" android:id="@+id/menu_future_dates_none"/>
+    <item android:title="@string/future_dates_30" android:id="@+id/menu_future_dates_30"/>
+    <item android:title="@string/future_dates_60" android:id="@+id/menu_future_dates_60"/>
+    <item android:title="@string/future_dates_90" android:id="@+id/menu_future_dates_90"/>
+    <item android:title="@string/future_dates_180" android:id="@+id/menu_future_dates_180"/>
+    <item android:title="@string/future_dates_365" android:id="@+id/menu_future_dates_365"/>
+    <item android:title="@string/future_dates_all" android:id="@+id/menu_future_dates_all"/>
+</menu>
\ No newline at end of file