-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
Closes #1092 - Fixed contents cut off on smaller screen issue. #1095
Changes from 3 commits
fd408b7
92433b6
b44d998
b0008cd
8d95b7b
3e5ed01
89ab029
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,9 @@ | |
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.util.DisplayMetrics; | ||
import android.util.Log; | ||
import android.util.TypedValue; | ||
import android.view.GestureDetector; | ||
import android.view.LayoutInflater; | ||
import android.view.Menu; | ||
|
@@ -29,6 +31,7 @@ | |
import androidx.appcompat.view.ActionMode; | ||
import androidx.appcompat.widget.SearchView; | ||
import androidx.core.splashscreen.SplashScreen; | ||
import androidx.core.widget.TextViewCompat; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.google.android.material.dialog.MaterialAlertDialogBuilder; | ||
|
@@ -55,6 +58,8 @@ public class MainActivity extends CatimaAppCompatActivity implements LoyaltyCard | |
private static final String TAG = "Catima"; | ||
public static final String RESTART_ACTIVITY_INTENT = "restart_activity_intent"; | ||
|
||
private static final int MEDIUM_SCALE_FACTOR_DIP = 460; | ||
|
||
private SQLiteDatabase mDatabase; | ||
private LoyaltyCardCursorAdapter mAdapter; | ||
private ActionMode mCurrentActionMode; | ||
|
@@ -178,37 +183,33 @@ public boolean onActionItemClicked(ActionMode inputMode, MenuItem inputItem) { | |
dialog.show(); | ||
|
||
return true; | ||
} | ||
else if(inputItem.getItemId() == R.id.action_archive){ | ||
} else if (inputItem.getItemId() == R.id.action_archive) { | ||
for (LoyaltyCard loyaltyCard : mAdapter.getSelectedItems()) { | ||
Log.d(TAG, "Archiving card: " + loyaltyCard.id); | ||
DBHelper.updateLoyaltyCardArchiveStatus(mDatabase, loyaltyCard.id,1); | ||
DBHelper.updateLoyaltyCardArchiveStatus(mDatabase, loyaltyCard.id, 1); | ||
updateLoyaltyCardList(false); | ||
inputMode.finish(); | ||
invalidateOptionsMenu(); | ||
} | ||
return true; | ||
} | ||
else if(inputItem.getItemId() == R.id.action_unarchive){ | ||
} else if (inputItem.getItemId() == R.id.action_unarchive) { | ||
for (LoyaltyCard loyaltyCard : mAdapter.getSelectedItems()) { | ||
Log.d(TAG, "Unarchiving card: " + loyaltyCard.id); | ||
DBHelper.updateLoyaltyCardArchiveStatus(mDatabase, loyaltyCard.id,0); | ||
DBHelper.updateLoyaltyCardArchiveStatus(mDatabase, loyaltyCard.id, 0); | ||
updateLoyaltyCardList(false); | ||
inputMode.finish(); | ||
invalidateOptionsMenu(); | ||
} | ||
return true; | ||
} | ||
else if(inputItem.getItemId() == R.id.action_star){ | ||
} else if (inputItem.getItemId() == R.id.action_star) { | ||
for (LoyaltyCard loyaltyCard : mAdapter.getSelectedItems()) { | ||
Log.d(TAG, "Starring card: " + loyaltyCard.id); | ||
DBHelper.updateLoyaltyCardStarStatus(mDatabase, loyaltyCard.id, 1); | ||
updateLoyaltyCardList(false); | ||
inputMode.finish(); | ||
} | ||
return true; | ||
} | ||
else if(inputItem.getItemId() == R.id.action_unstar){ | ||
} else if (inputItem.getItemId() == R.id.action_unstar) { | ||
for (LoyaltyCard loyaltyCard : mAdapter.getSelectedItems()) { | ||
Log.d(TAG, "Unstarring card: " + loyaltyCard.id); | ||
DBHelper.updateLoyaltyCardStarStatus(mDatabase, loyaltyCard.id, 0); | ||
|
@@ -233,15 +234,14 @@ protected void onCreate(Bundle inputSavedInstanceState) { | |
extractIntentFields(getIntent()); | ||
SplashScreen.installSplashScreen(this); | ||
super.onCreate(inputSavedInstanceState); | ||
if(!mArchiveMode) { | ||
if (!mArchiveMode) { | ||
binding = MainActivityBinding.inflate(getLayoutInflater()); | ||
setTitle(R.string.app_name); | ||
setContentView(binding.getRoot()); | ||
setSupportActionBar(binding.toolbar); | ||
groupsTabLayout = binding.groups; | ||
contentMainBinding = ContentMainBinding.bind(binding.include.getRoot()); | ||
} | ||
else{ | ||
} else { | ||
archiveActivityBinding = ArchiveActivityBinding.inflate(getLayoutInflater()); | ||
setTitle(R.string.archiveList); | ||
setContentView(archiveActivityBinding.getRoot()); | ||
|
@@ -250,7 +250,7 @@ protected void onCreate(Bundle inputSavedInstanceState) { | |
contentMainBinding = ContentMainBinding.bind(archiveActivityBinding.include.getRoot()); | ||
} | ||
|
||
if(mArchiveMode){ | ||
if (mArchiveMode) { | ||
ActionBar actionBar = getSupportActionBar(); | ||
if (actionBar != null) { | ||
actionBar.setDisplayHomeAsUpEnabled(true); | ||
|
@@ -302,7 +302,6 @@ public void onTabReselected(TabLayout.Tab tab) { | |
mAdapter = new LoyaltyCardCursorAdapter(this, null, this); | ||
mCardList.setAdapter(mAdapter); | ||
registerForContextMenu(mCardList); | ||
|
||
mGroup = null; | ||
updateLoyaltyCardList(true); | ||
|
||
|
@@ -404,7 +403,9 @@ protected void onResume() { | |
groupsTabLayout.selectTab(tab); | ||
assert tab != null; | ||
mGroup = tab.getTag(); | ||
} | ||
} else | ||
scaleScreen(); | ||
|
||
updateLoyaltyCardList(true); | ||
// End of active tab logic | ||
|
||
|
@@ -592,9 +593,9 @@ public void updateTabGroups(TabLayout groupsTabLayout) { | |
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu inputMenu) { | ||
if(!mArchiveMode) | ||
if (!mArchiveMode) | ||
getMenuInflater().inflate(R.menu.main_menu, inputMenu); | ||
else{ | ||
else { | ||
getMenuInflater().inflate(R.menu.archive_menu, inputMenu); | ||
} | ||
|
||
|
@@ -632,7 +633,7 @@ public boolean onQueryTextChange(String newText) { | |
}); | ||
} | ||
|
||
if(!mArchiveMode) { | ||
if (!mArchiveMode) { | ||
if (DBHelper.getArchivedCardsCount(mDatabase) == 0) { | ||
inputMenu.findItem(R.id.action_archived).setVisible(false); | ||
} else { | ||
|
@@ -846,6 +847,16 @@ private void enableActionMode(int inputPosition) { | |
toggleSelection(inputPosition); | ||
} | ||
|
||
private void scaleScreen() { | ||
DisplayMetrics displayMetrics = new DisplayMetrics(); | ||
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); | ||
int screenHeight = displayMetrics.heightPixels; | ||
float mediumSizePx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,MEDIUM_SCALE_FACTOR_DIP,getResources().getDisplayMetrics()); | ||
boolean shouldScaleSmaller = screenHeight < mediumSizePx; | ||
|
||
binding.include.welcomeIcon.setVisibility(shouldScaleSmaller ? View.GONE : View.VISIBLE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't notice this before but it seems this crashes the archive option (you can confirm this by putting 1 card in archive and then clicking the menu in the top right and choosing "Archive"):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooops.. I didn't think about this scenario. It's now fixed in commit b0008cd |
||
} | ||
|
||
private void toggleSelection(int inputPosition) { | ||
mAdapter.toggleSelection(inputPosition); | ||
int count = mAdapter.getSelectedItemCount(); | ||
|
@@ -864,11 +875,10 @@ private void toggleSelection(int inputPosition) { | |
boolean hasStarred = false; | ||
boolean hasUnstarred = false; | ||
|
||
if(!mArchiveMode) { | ||
if (!mArchiveMode) { | ||
unarchiveItem.setVisible(false); | ||
archiveItem.setVisible(true); | ||
} | ||
else{ | ||
} else { | ||
unarchiveItem.setVisible(true); | ||
archiveItem.setVisible(false); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For single if statements I kinda get the no-brackets style (although I personally wouldn't use it), but I'd really prefer brackets here. For me personally, it is a lot more readable.