Skip to content

Commit 2526ffe

Browse files
Popups, BDialog flags, Small ui changes, New Updating Mechanism (via releases)
1 parent 25300bc commit 2526ffe

26 files changed

+563
-600
lines changed

apks/app-release.apk

3.31 KB
Binary file not shown.

apks/last_release.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
75@@@11.2.0@@@Fixed Bug in Alarms
1+
76@@@11.3.0@@@ # Introducing Popups!
2+
# Small UI changes

app/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ android {
2727
applicationId "com.bald.uriah.baldphone"
2828
minSdkVersion 21
2929
targetSdkVersion 28
30-
versionCode 75
31-
versionName "11.2.0"
30+
versionCode 76
31+
versionName "11.3.0"
3232
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3333
}
3434
buildTypes {
@@ -60,8 +60,8 @@ dependencies {
6060
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
6161
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
6262
testImplementation 'junit:junit:4.12'
63-
androidTestImplementation 'androidx.test:runner:1.2.0-alpha05'
64-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha05'
63+
androidTestImplementation 'androidx.test:runner:1.2.0-beta01'
64+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-beta01'
6565
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
6666
implementation 'com.google.android.material:material:1.1.0-alpha05'
6767
implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
@@ -73,5 +73,6 @@ dependencies {
7373
implementation 'com.android.volley:volley:1.1.1'
7474
implementation "ch.acra:acra-http:5.3.0"
7575
implementation 'androidx.exifinterface:exifinterface:1.1.0-alpha01'
76-
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.3' //for adding pic to contact
76+
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.3'
77+
androidTestImplementation 'androidx.test:rules:1.2.0-beta01'//for adding pic to contact
7778
}

app/src/main/java/com/bald/uriah/baldphone/activities/AppsActivity.java

Lines changed: 78 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,15 @@
1919

2020
package com.bald.uriah.baldphone.activities;
2121

22-
import android.animation.ValueAnimator;
2322
import android.content.ComponentName;
2423
import android.content.Intent;
2524
import android.graphics.Point;
26-
import android.graphics.drawable.Drawable;
2725
import android.net.Uri;
2826
import android.os.Bundle;
29-
import android.util.TypedValue;
3027
import android.view.View;
3128
import android.view.WindowManager;
32-
import android.widget.ImageView;
33-
import android.widget.TextView;
34-
import androidx.constraintlayout.widget.ConstraintLayout;
35-
import androidx.core.content.ContextCompat;
29+
import android.widget.PopupWindow;
30+
import androidx.annotation.NonNull;
3631
import androidx.recyclerview.widget.GridLayoutManager;
3732
import androidx.recyclerview.widget.RecyclerView;
3833
import com.bald.uriah.baldphone.R;
@@ -42,9 +37,12 @@
4237
import com.bald.uriah.baldphone.databases.apps.AppsDatabaseHelper;
4338
import com.bald.uriah.baldphone.utils.BDB;
4439
import com.bald.uriah.baldphone.utils.BDialog;
40+
import com.bald.uriah.baldphone.utils.DropDownRecyclerViewAdapter;
4541
import com.bald.uriah.baldphone.utils.S;
42+
import com.bumptech.glide.Glide;
4643

4744
import java.util.List;
45+
import java.util.Objects;
4846

4947
import static com.bald.uriah.baldphone.adapters.AppsRecyclerViewAdapter.TYPE_HEADER;
5048

@@ -55,19 +53,11 @@ public class AppsActivity extends com.bald.uriah.baldphone.activities.BaldActivi
5553
public static final int UNINSTALL_REQUEST_CODE = 52;
5654
private static final String TAG = AppsActivity.class.getSimpleName();
5755
private static final String SELECTED_APP_INDEX = "SELECTED_APP_INDEX";
58-
private static final int TIME_FOR_EFFECT = 300;
59-
private int lastIndex = -1;
6056

6157
//"finals"
6258
private AppsDatabase appsDatabase;
63-
private Drawable drawablePin, drawableRemPin;
6459
private int numberOfAppsInARow;
65-
private int barHeight;
6660

67-
//views
68-
private View bar, pin, open, uninstall;
69-
private TextView tv_add_or_rem_shortcut;
70-
private ImageView iv_pin;
7161
private RecyclerView recyclerView;
7262

7363
private AppsRecyclerViewAdapter appsRecyclerViewAdapter;
@@ -79,16 +69,12 @@ protected void onCreate(Bundle savedInstanceState) {
7969

8070
AppsDatabaseHelper.updateDB(this);
8171

82-
drawablePin = ContextCompat.getDrawable(this, R.drawable.add_on_button);
83-
drawableRemPin = ContextCompat.getDrawable(this, R.drawable.remove_on_button);
84-
barHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 120f, getResources().getDisplayMetrics());
85-
8672
appsDatabase = AppsDatabase.getInstance(AppsActivity.this);
8773
final List<App> appList = appsDatabase.appsDatabaseDao().getAllOrderedByABC();
8874
attachXml();
8975

9076
final boolean modeChoose = MODE_CHOOSE_ONE.equals(getIntent().getStringExtra(EXTRA_MODE));
91-
appsRecyclerViewAdapter = new AppsRecyclerViewAdapter(appList, this, modeChoose ? this::appChosen : this::changeBar, recyclerView);
77+
appsRecyclerViewAdapter = new AppsRecyclerViewAdapter(appList, this, modeChoose ? this::appChosen : this::showDropDown, recyclerView);
9278

9379
final WindowManager windowManager = getWindowManager();
9480
final Point point = new Point();
@@ -110,57 +96,11 @@ public int getSpanSize(int position) {
11096
}
11197
});
11298
recyclerView.setLayoutManager(gridLayoutManager);
113-
114-
open.setOnClickListener(v -> {
115-
if (appsRecyclerViewAdapter.index != -1) {
116-
final ComponentName componentName = ComponentName.unflattenFromString(((App) appsRecyclerViewAdapter.dataList.get(appsRecyclerViewAdapter.index)).getFlattenComponentName());
117-
S.startComponentName(v.getContext(), componentName);
118-
}
119-
});
120-
pin.setOnClickListener(v -> {
121-
if (appsRecyclerViewAdapter.index != -1) {
122-
123-
final App app = (App) appsRecyclerViewAdapter.dataList.get(appsRecyclerViewAdapter.index);
124-
if (app.isPinned()) {
125-
appsDatabase.appsDatabaseDao().update(app.getId(), false);
126-
app.setPinned(false);
127-
appsRecyclerViewAdapter.notifyItemChanged(appsRecyclerViewAdapter.index);
128-
iv_pin.setImageDrawable(drawablePin);
129-
tv_add_or_rem_shortcut.setText(R.string.add_shortcut);
130-
} else {
131-
appsDatabase.appsDatabaseDao().update(app.getId(), true);
132-
app.setPinned(true);
133-
appsRecyclerViewAdapter.notifyItemChanged(appsRecyclerViewAdapter.index);
134-
iv_pin.setImageDrawable(drawableRemPin);
135-
tv_add_or_rem_shortcut.setText(R.string.remove_shortcut);
136-
137-
}
138-
}
139-
});
140-
uninstall.setOnClickListener(v -> {
141-
final App app = (App) appsRecyclerViewAdapter.dataList.get(appsRecyclerViewAdapter.index);
142-
BDB.from(this)
143-
.setTitle(getText(R.string.uninstall) + app.getLabel())
144-
.setSubText(String.format(getString(R.string.uninstall_subtext), app.getLabel(), app.getLabel()))
145-
.setDialogState(BDialog.DialogState.YES_CANCEL)
146-
.setCancelable(true)
147-
.setPositiveButtonListener(params -> {
148-
uninstallApp(app);
149-
return true;
150-
})
151-
.show();
152-
});
15399
recyclerView.setAdapter(appsRecyclerViewAdapter);
154100
}
155101

156102
private void attachXml() {
157103
recyclerView = findViewById(R.id.rc_apps);
158-
bar = findViewById(R.id.bar);
159-
pin = bar.findViewById(R.id.pin);
160-
open = bar.findViewById(R.id.open);
161-
uninstall = bar.findViewById(R.id.app_uninstall);
162-
iv_pin = findViewById(R.id.iv_pin);
163-
tv_add_or_rem_shortcut = findViewById(R.id.tv_add_or_rem_shortcut);
164104
}
165105

166106
private void uninstallApp(App app) {
@@ -181,57 +121,89 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
181121
}
182122
}
183123

184-
private void changeBar(int index) {
185-
if (lastIndex == index)
124+
private void showDropDown(final int index) {
125+
appsRecyclerViewAdapter.index = index;
126+
final App app = (App) appsRecyclerViewAdapter.dataList.get(index);
127+
final View view = Objects.requireNonNull(recyclerView.getLayoutManager()).findViewByPosition(index);
128+
if (view == null)
186129
return;
187-
lastIndex = index;
188-
if (index == -1) {
189-
animateBarView(false);
190-
} else {
191-
final App app = (App) appsRecyclerViewAdapter.dataList.get(index);
192-
bar.setVisibility(View.VISIBLE);
193-
animateBarView(true);
194-
if (index + numberOfAppsInARow >= appsRecyclerViewAdapter.dataList.size())
195-
recyclerView.scrollToPosition(index);
130+
S.showDropDownPopup(this, recyclerView.getWidth(), new DropDownRecyclerViewAdapter.DropDownListener() {
131+
@Override
132+
public void onUpdate(DropDownRecyclerViewAdapter.ViewHolder viewHolder, int position, PopupWindow popupWindow) {
133+
switch (position) {
134+
case 0:
135+
viewHolder.pic.setImageResource(R.drawable.delete_on_button);
136+
viewHolder.text.setText(R.string.uninstall);
137+
viewHolder.itemView.setOnClickListener(v1 -> {
138+
BDB.from(AppsActivity.this)
139+
.setTitle(String.format("%s %s", getText(R.string.uninstall), app.getLabel()))
140+
.setSubText(String.format(getString(R.string.uninstall_subtext), app.getLabel(), app.getLabel()))
141+
.addFlag(BDialog.FLAG_YES | BDialog.FLAG_CANCEL)
142+
.setPositiveButtonListener(params -> {
143+
uninstallApp(app);
144+
return true;
145+
})
146+
.show();
147+
popupWindow.dismiss();
148+
});
149+
break;
150+
case 1:
151+
Glide.with(viewHolder.pic).load(app.getIcon()).into(viewHolder.pic);
152+
viewHolder.text.setText(R.string.open);
153+
viewHolder.itemView.setOnClickListener(v1 -> {
154+
final ComponentName componentName = ComponentName.unflattenFromString(app.getFlattenComponentName());
155+
S.startComponentName(AppsActivity.this, componentName);
156+
popupWindow.dismiss();
157+
});
158+
break;
159+
case 2:
160+
viewHolder.pic.setImageResource(app.isPinned() ? R.drawable.remove_on_button : R.drawable.add_on_button);
161+
viewHolder.text.setText(app.isPinned() ? R.string.remove_shortcut : R.string.add_shortcut);
162+
viewHolder.itemView.setOnClickListener(v1 -> {
163+
if (app.isPinned()) {
164+
appsDatabase.appsDatabaseDao().update(app.getId(), false);
165+
app.setPinned(false);
166+
appsRecyclerViewAdapter.notifyItemChanged(appsRecyclerViewAdapter.index);
167+
} else {
168+
appsDatabase.appsDatabaseDao().update(app.getId(), true);
169+
app.setPinned(true);
170+
appsRecyclerViewAdapter.notifyItemChanged(appsRecyclerViewAdapter.index);
171+
}
172+
popupWindow.dismiss();
173+
showDropDown(index);
174+
});
175+
break;
176+
}
177+
}
196178

197-
if (app.isPinned()) {
198-
tv_add_or_rem_shortcut.setText(R.string.remove_shortcut);
199-
iv_pin.setImageDrawable(drawableRemPin);
200-
} else {
201-
iv_pin.setImageDrawable(drawablePin);
202-
tv_add_or_rem_shortcut.setText(R.string.add_shortcut);
179+
@Override public int size() {
180+
return 3;
203181
}
204-
}
182+
183+
@Override public void onDismiss() {
184+
if (appsRecyclerViewAdapter.lastView != null)
185+
appsRecyclerViewAdapter.lastView.setClicked(false);
186+
appsRecyclerViewAdapter.lastView = null;
187+
appsRecyclerViewAdapter.index = -1;
188+
189+
}
190+
}, view);
191+
192+
if (index + numberOfAppsInARow >= appsRecyclerViewAdapter.dataList.size())
193+
recyclerView.scrollToPosition(index);
194+
205195
}
206196

207197
private void appChosen(int index) {
208-
if (lastIndex == index)
209-
return;
210-
lastIndex = index;
211-
if (index == -1) {
212-
animateBarView(false);
213-
} else {
198+
if (index != -1) {
214199
final App app = (App) appsRecyclerViewAdapter.dataList.get(index);
215200
setResult(RESULT_OK, new Intent().setComponent(ComponentName.unflattenFromString(app.getFlattenComponentName())));
216201
finish();
217202
}
218203
}
219204

220-
public void animateBarView(boolean up) {
221-
final int desiredInt = up ? barHeight : 0;
222-
final ValueAnimator animator = ValueAnimator.ofInt(((ConstraintLayout.LayoutParams) bar.getLayoutParams()).height, desiredInt);
223-
animator.addUpdateListener(valueAnimator -> {
224-
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) bar.getLayoutParams();
225-
params.height = (Integer) valueAnimator.getAnimatedValue();
226-
bar.setLayoutParams(params);
227-
}
228-
);
229-
animator.setDuration(TIME_FOR_EFFECT);
230-
animator.start();
231-
}
232-
233205
@Override
234-
protected void onSaveInstanceState(Bundle outState) {
206+
protected void onSaveInstanceState(@NonNull Bundle outState) {
235207
super.onSaveInstanceState(outState);
236208
outState.putInt(SELECTED_APP_INDEX, ((AppsRecyclerViewAdapter) recyclerView.getAdapter()).index);
237209
}
@@ -243,7 +215,8 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) {
243215
final AppsRecyclerViewAdapter adapter = ((AppsRecyclerViewAdapter) recyclerView.getAdapter());
244216
if (index < adapter.dataList.size() && index > 0 && adapter.dataList.get(index).type() != TYPE_HEADER) {
245217
adapter.index = index;
246-
changeBar(index);
218+
recyclerView.getLayoutManager().scrollToPosition(index);
219+
recyclerView.post(() -> showDropDown(index));
247220
}
248221
}
249222

app/src/main/java/com/bald/uriah/baldphone/activities/BaldActivity.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,14 @@ public void onBackPressed() {
220220
}
221221

222222
public void autoDismiss(Dialog dialog) {
223+
if (dialogsToClose.size() > 10)
224+
dialogsToClose = S.cleanWeakList(dialogsToClose);
223225
dialogsToClose.add(new WeakReference<>(dialog));
224226
}
225227

226228
public void autoDismiss(PopupWindow popupWindow) {
229+
if (popupWindowsToClose.size() > 10)
230+
popupWindowsToClose = S.cleanWeakList(popupWindowsToClose);
227231
popupWindowsToClose.add(new WeakReference<>(popupWindow));
228232
}
229233

@@ -248,8 +252,7 @@ private void accidentalTouchChecker() {
248252
BDB.from(this)
249253
.setTitle(R.string.accidental_touches)
250254
.setSubText(R.string.accidental_touches_subtext)
251-
.setDialogState(BDialog.DialogState.OK)
252-
.setCancelable(false)
255+
.addFlag(BDialog.FLAG_NOT_CANCELABLE | BDialog.FLAG_OK)
253256
.setPositiveButtonListener(params -> {
254257
touches = 0;
255258
accidentalMinTouches += 2;
@@ -289,9 +292,4 @@ protected void setupYoutube(int index) {
289292

290293
protected abstract int requiredPermissions();
291294

292-
/**
293-
* @return time in milliseconds for tha activity to stay on.
294-
* if it returns -1 activity will time out as set in device settings
295-
*/
296-
297295
}

0 commit comments

Comments
 (0)