Skip to content

This pull request enables new group widgets #669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 52 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7fca6db
Add code 93
Dec 7, 2021
e727a27
Merge remote-tracking branch 'origin/master'
Dec 8, 2021
8c86fa8
Fix long press to add card to group
Dec 9, 2021
a15cc31
Merge remote-tracking branch 'origin/master'
Dec 9, 2021
4304a51
Merge remote-tracking branch 'origin/master'
Dec 9, 2021
7cf8d89
First step to implement group widget
Dec 9, 2021
2504a24
Try to fix (try with a standard list view)
Dec 9, 2021
4a5f517
Try to fix with group cursors
Dec 9, 2021
1bfff05
Blank list, fix with GroupCursorAdapter
Dec 9, 2021
a8f9baf
implement GroupCursorAdapter
Dec 9, 2021
a6aa6f6
implement click action
Dec 10, 2021
10da2a7
try fixes with renaming groupListListItemViewHolder
Dec 10, 2021
5a074db
try fixes with onResume group view
Dec 10, 2021
8078f0c
try fixes with updateLoyaltyCardList()
Dec 10, 2021
d57f26e
try fixes with groupTabs selectTab
Dec 10, 2021
d3c2412
fix, just set selectedTab
Dec 10, 2021
30f1381
Revert some changes to see if the app starts again correctly :/
Dec 10, 2021
36cdbd1
Select group for widget
Dec 10, 2021
7563bee
fix select button class
Dec 10, 2021
004df4a
Merge branch 'master' of https://github.com/TheLastProject/Catima int…
Dec 10, 2021
b61ed93
Add onResume group widget logic
Dec 10, 2021
22dbd1d
Add elements to onResume group widget logic
Dec 10, 2021
ff2d23e
Fixes to onResume
Dec 10, 2021
a1e9bfb
Fixes to MainActivity.java
Dec 10, 2021
dc8fd57
Respect order and orderDirection when opening a widget
Dec 10, 2021
9b13be0
Edit and delete group shortcuts implemented
Dec 10, 2021
2548759
Fix edit group shortcut
Dec 10, 2021
0d8acbf
Group not found implemented
Dec 11, 2021
b5ab5d7
Revert some wrong shortcut related commits
Dec 11, 2021
ec95b0b
Simplify MainActivity.java
Dec 12, 2021
a0c0332
Merge branch 'master' into group-widget-2
Altonss Dec 12, 2021
ed84142
Update MainActivity.java
Altonss Dec 12, 2021
b7d20f3
Several fixes:
Dec 13, 2021
5681326
Fix missing group error message: make groupWidget string not final
Dec 13, 2021
5092731
Fix MainActivity
Dec 13, 2021
d6b82bb
Merge remote-tracking branch 'origin/master'
Dec 13, 2021
ec06134
Fix icon and shortcutId
Dec 14, 2021
90dfa93
Set GroupShortcut to use Catima Icon
Dec 14, 2021
e36657e
Add fix in ShortcutBuilder with intent flags
Dec 14, 2021
5e2cbd9
Fix LoyaltyCardEditActivity according to Android studio
Dec 15, 2021
7bc52a7
Merge remote-tracking branch 'origin/master'
Dec 15, 2021
8284293
Merge branch 'master' into group-widget-2
Dec 15, 2021
2fd7292
Merge new db changes
Dec 15, 2021
0b4e4be
Small fix (make spotbugs happy :))
Dec 15, 2021
b5dae66
Merge remote-tracking branch 'origin/master' into group-widget-2
Mar 27, 2022
bc9fc4f
Merge current master branch into this branch, to keep it up to date w…
Apr 2, 2022
f58bb48
Merge remote-tracking branch 'origin/master' into group-widget-2
May 25, 2022
608dd76
Small improvement
May 25, 2022
fecad9c
Merge branch 'master' into group-widget-2
Altonss Jul 24, 2022
1301e61
Small improvements and fix extract intent
Jul 24, 2022
02f2ab1
Fix bugs
Sep 21, 2022
aa53837
Merge remote-tracking branch 'origin/master' into group-widget-2
Sep 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".GroupShortcutConfigure"
android:exported="true"
android:label="@string/groupShortcut"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<activity
android:name=".UCropWrapper"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package protect.card_locker;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatButton;
import androidx.recyclerview.widget.RecyclerView;

import protect.card_locker.preferences.Settings;

public class GroupSelectCursorAdapter extends BaseCursorAdapter<GroupSelectCursorAdapter.GroupListItemViewHolder> {
Settings mSettings;
private final Context mContext;
private final GroupAdapterListener mListener;
SQLiteDatabase mDatabase;

public GroupSelectCursorAdapter(Context inputContext, Cursor inputCursor, GroupAdapterListener inputListener) {
super(inputCursor, DBHelper.LoyaltyCardDbGroups.ORDER);
setHasStableIds(true);
mSettings = new Settings(inputContext);
mContext = inputContext.getApplicationContext();
mListener = inputListener;
mDatabase = new DBHelper(inputContext).getReadableDatabase();

swapCursor(inputCursor);
}

@NonNull
@Override
public GroupSelectCursorAdapter.GroupListItemViewHolder onCreateViewHolder(ViewGroup inputParent, int inputViewType) {
View itemView = LayoutInflater.from(inputParent.getContext()).inflate(R.layout.group_select_layout, inputParent, false);
return new GroupListItemViewHolder(itemView);
}

public void onBindViewHolder(GroupListItemViewHolder inputHolder, Cursor inputCursor) {
Group group = Group.toGroup(inputCursor);

inputHolder.mName.setText(group._id);

int groupCardCount = DBHelper.getGroupCardCount(mDatabase, group._id);
inputHolder.mCardCount.setText(mContext.getResources().getQuantityString(R.plurals.groupCardCount, groupCardCount, groupCardCount));

inputHolder.mName.setTextSize(mSettings.getFontSizeMax(mSettings.getMediumFont()));
inputHolder.mCardCount.setTextSize(mSettings.getFontSizeMax(mSettings.getSmallFont()));

applyClickEvents(inputHolder);
}

private void applyClickEvents(GroupListItemViewHolder inputHolder) {
inputHolder.mSelect.setOnClickListener(view -> mListener.onSelectButtonClicked(inputHolder.itemView));
}

public interface GroupAdapterListener {
void onSelectButtonClicked(View view);
}

public static class GroupListItemViewHolder extends RecyclerView.ViewHolder {
public TextView mName, mCardCount;
public AppCompatButton mSelect;

public GroupListItemViewHolder(View inputView) {
super(inputView);
mName = inputView.findViewById(R.id.name);
mCardCount = inputView.findViewById(R.id.cardCount);
mSelect = inputView.findViewById(R.id.select);
}
}
}
81 changes: 81 additions & 0 deletions app/src/main/java/protect/card_locker/GroupShortcutConfigure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package protect.card_locker;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.widget.Toolbar;
import androidx.core.content.pm.ShortcutInfoCompat;
import androidx.core.content.pm.ShortcutManagerCompat;
import androidx.recyclerview.widget.RecyclerView;

/**
* The configuration screen for creating a shortcut.
*/
public class GroupShortcutConfigure extends CatimaAppCompatActivity implements GroupSelectCursorAdapter.GroupAdapterListener {
static final String TAG = "Catima";
private SQLiteDatabase mDatabase;

@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);

mDatabase = new DBHelper(this).getReadableDatabase();


// Set the result to CANCELED. This will cause nothing to happen if the
// aback button is pressed.
setResult(RESULT_CANCELED);

setContentView(R.layout.simple_toolbar_list_activity);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(R.string.shortcutSelectGroup);

// If there are no groups, bail
if (DBHelper.getGroupCount(mDatabase) == 0) {
Toast.makeText(this, R.string.noGroups, Toast.LENGTH_LONG).show();
finish();
}

final RecyclerView groupList = findViewById(R.id.list);

Cursor groupCursor = DBHelper.getGroupCursor(mDatabase);
final GroupSelectCursorAdapter adapter = new GroupSelectCursorAdapter(this, groupCursor,this);
groupList.setAdapter(adapter);
}

private String getGroupName(View view) {
TextView groupNameTextView = view.findViewById(R.id.name);
return (String) groupNameTextView.getText();
}

private void onClickAction(View view) {
String groupId = getGroupName(view);
if (groupId == null) {
throw (new IllegalArgumentException("The widget expects a group"));
}
Log.d("groupId", "groupId: " + groupId);
Group group = DBHelper.getGroup(mDatabase, groupId);
if (group == null) {
throw (new IllegalArgumentException("cannot load group " + groupId + " from database"));
}

Log.d(TAG, "Creating shortcut for group " + group._id + "," + group._id);

ShortcutInfoCompat shortcut = ShortcutHelper.createGroupShortcutBuilder(GroupShortcutConfigure.this, group).build();

setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(GroupShortcutConfigure.this, shortcut));

finish();
}

@Override
public void onSelectButtonClicked(View view) {
onClickAction(view);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.google.android.material.tabs.TabLayout;
import com.jaredrummler.android.colorpicker.ColorPickerDialog;
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener;
import com.yalantis.ucrop.BuildConfig;
import com.yalantis.ucrop.UCrop;
import com.yalantis.ucrop.model.AspectRatio;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,6 @@ public void onBackPressed() {
setFullscreen(false);
return;
}

super.onBackPressed();
}

Expand Down
54 changes: 41 additions & 13 deletions app/src/main/java/protect/card_locker/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard
private View mNoMatchingCardsText;
private View mNoGroupCardsText;

private String groupWidget = null;

private boolean mArchiveMode;
public static final String BUNDLE_ARCHIVE_MODE = "archiveMode";

Expand Down Expand Up @@ -225,6 +227,16 @@ public void onDestroyActionMode(ActionMode inputMode) {
}
};

private void extractIntentFields(Intent intent)
{
final Bundle b = intent.getExtras();
groupWidget = b != null ? b.getString("groupId") : null;
mArchiveMode = b != null && b.getBoolean(BUNDLE_ARCHIVE_MODE, false);
if(!mArchiveMode) {
Log.d(TAG, "View activity: id=" + groupWidget);
}
}

@Override
protected void onCreate(Bundle inputSavedInstanceState) {
extractIntentFields(getIntent());
Expand All @@ -238,7 +250,7 @@ protected void onCreate(Bundle inputSavedInstanceState) {
setTitle(R.string.archiveList);
setContentView(R.layout.archive_activity);
}

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

Expand Down Expand Up @@ -378,10 +390,25 @@ protected void onResume() {
updateTabGroups(groupsTabLayout);

// Restore settings from Shared Preference
SharedPreferences activeTabPref = getApplicationContext().getSharedPreferences(
getString(R.string.sharedpreference_active_tab),
Context.MODE_PRIVATE);
selectedTab = activeTabPref.getInt(getString(R.string.sharedpreference_active_tab), 0);
if (groupWidget != null){
Group groupSelected = DBHelper.getGroup(mDatabase, groupWidget);
if (groupSelected == null) {
Log.w(TAG, "Could not lookup group " + groupWidget);
Toast.makeText(this, R.string.noGroupExistsError, Toast.LENGTH_LONG).show();
finish();
return;
}
else{
selectedTab = groupSelected.order+1;
}
}
else {
SharedPreferences activeTabPref = getApplicationContext().getSharedPreferences(
getString(R.string.sharedpreference_active_tab),
Context.MODE_PRIVATE);
selectedTab = activeTabPref.getInt(getString(R.string.sharedpreference_active_tab), 0);
}

SharedPreferences sortPref = getApplicationContext().getSharedPreferences(
getString(R.string.sharedpreference_sort),
Context.MODE_PRIVATE);
Expand All @@ -404,6 +431,7 @@ protected void onResume() {
mGroup = tab.getTag();
}
updateLoyaltyCardList(true);
groupWidget = null;
// End of active tab logic

if (!mArchiveMode) {
Expand Down Expand Up @@ -498,11 +526,6 @@ private void updateLoyaltyCardList(boolean updateCount) {
}
}

private void extractIntentFields(Intent intent) {
final Bundle b = intent.getExtras();
mArchiveMode = b != null && b.getBoolean(BUNDLE_ARCHIVE_MODE, false);
}

public void updateTabGroups(TabLayout groupsTabLayout) {
List<Group> newGroups = DBHelper.getGroups(mDatabase);

Expand Down Expand Up @@ -538,9 +561,6 @@ public boolean onCreateOptionsMenu(Menu inputMenu) {
getMenuInflater().inflate(R.menu.archive_menu, inputMenu);
}

Utils.updateMenuCardDetailsButtonState(inputMenu.findItem(R.id.action_unfold), mAdapter.showingDetails());
displayCardSetupOptions(inputMenu, mLoyaltyCardCount > 0);

SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
if (searchManager != null) {
mSearchView = (SearchView) inputMenu.findItem(R.id.action_search).getActionView();
Expand Down Expand Up @@ -885,4 +905,12 @@ public void onRowClicked(int inputPosition) {
startActivity(intent);
}
}

@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);

Log.i(TAG, "Received new intent");
extractIntentFields(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,5 @@ public void onRowLongClicked(int inputPosition) {
@Override
public void onRowClicked(int inputPosition) {
mAdapter.toggleSelection(inputPosition);

}
}
31 changes: 29 additions & 2 deletions app/src/main/java/protect/card_locker/ShortcutHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ static ShortcutInfoCompat.Builder createShortcutBuilder(Context context, Loyalty
intent.setAction(Intent.ACTION_MAIN);
// Prevent instances of the view activity from piling up; if one exists let this
// one replace it.
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

final Bundle bundle = new Bundle();
bundle.putInt("id", loyaltyCard.id);
bundle.putBoolean("view", true);
Expand All @@ -149,11 +153,34 @@ static ShortcutInfoCompat.Builder createShortcutBuilder(Context context, Loyalty
}

IconCompat icon = IconCompat.createWithAdaptiveBitmap(iconBitmap);

return new ShortcutInfoCompat.Builder(context, Integer.toString(loyaltyCard.id))
.setShortLabel(loyaltyCard.store)
.setLongLabel(loyaltyCard.store)
.setIntent(intent)
.setIcon(icon);
}
static ShortcutInfoCompat.Builder createGroupShortcutBuilder(Context context, Group group) {
Intent intent = new Intent(context, MainActivity.class);
intent.setAction(Intent.ACTION_MAIN);
// Prevent instances of the view activity from piling up; if one exists let this
// one replace it.
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
final Bundle bundle = new Bundle();
// Done like with the cards but with group._id (a string)
bundle.putString("groupId", group._id);
intent.putExtras(bundle);

String shortcutId = "GROUP_" + group._id;

IconCompat shortcutIcon= IconCompat.createWithResource(context, R.mipmap.ic_launcher);

return new ShortcutInfoCompat.Builder(context, shortcutId)
.setShortLabel(group._id)
.setLongLabel(group._id)
.setIntent(intent)
.setIcon(shortcutIcon);
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/group_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
android:clipToPadding="false"
android:scrollbars="vertical"
android:visibility="gone" />

</RelativeLayout>
Loading