修改弹窗逻辑
This commit is contained in:
parent
734c4bc2b4
commit
196e960177
@ -25,7 +25,6 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isShrinkResources = true
|
||||
isMinifyEnabled = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
|
||||
@ -23,7 +23,9 @@ import com.tool.applockpro.adapter.AppAdapter;
|
||||
import com.tool.applockpro.data.MyDataBase;
|
||||
import com.tool.applockpro.data.Mydata;
|
||||
import com.tool.applockpro.databinding.ActivitySearchBinding;
|
||||
import com.tool.applockpro.fragment.OkDialogFragment;
|
||||
import com.tool.applockpro.tool.Mytools;
|
||||
import com.tool.applockpro.tool.ShowAdDialogCallback;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -31,7 +33,7 @@ import java.util.List;
|
||||
public class SearchActivity extends AppCompatActivity {
|
||||
ActivitySearchBinding binding;
|
||||
private List<Mydata> searchdata = new ArrayList<>();
|
||||
|
||||
private OkDialogFragment okDialogFragment;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -92,7 +94,12 @@ public class SearchActivity extends AppCompatActivity {
|
||||
} else {
|
||||
binding.searchTips.setVisibility(View.GONE);
|
||||
binding.searchRv.setVisibility(View.VISIBLE);
|
||||
AppAdapter appAdapter = new AppAdapter(SearchActivity.this, SearchActivity.this);
|
||||
AppAdapter appAdapter = new AppAdapter(SearchActivity.this, SearchActivity.this, new ShowAdDialogCallback() {
|
||||
@Override
|
||||
public void onShowAdOkDialog(String msg) {
|
||||
showDialog(msg);
|
||||
}
|
||||
});
|
||||
appAdapter.update(searchdata);
|
||||
binding.searchRv.setAdapter(appAdapter);
|
||||
binding.searchRv.setLayoutManager(new LinearLayoutManager(SearchActivity.this));
|
||||
@ -105,7 +112,14 @@ public class SearchActivity extends AppCompatActivity {
|
||||
}
|
||||
hideKeyView();
|
||||
}
|
||||
|
||||
private void showDialog(String string) {
|
||||
if (okDialogFragment == null) {
|
||||
okDialogFragment = OkDialogFragment.newInstance(string);
|
||||
}else {
|
||||
okDialogFragment.updateContent(string);
|
||||
}
|
||||
okDialogFragment.show(getSupportFragmentManager(), "");
|
||||
}
|
||||
private void initData() {
|
||||
|
||||
binding.searchTips.setVisibility(View.GONE);
|
||||
|
||||
@ -16,6 +16,7 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@ -26,9 +27,12 @@ import com.tool.applockpro.ApplockSkin;
|
||||
import com.tool.applockpro.R;
|
||||
import com.tool.applockpro.data.MyDataBase;
|
||||
import com.tool.applockpro.data.Mydata;
|
||||
import com.tool.applockpro.fragment.OkDialogFragment;
|
||||
import com.tool.applockpro.tool.AdActionListener;
|
||||
import com.tool.applockpro.tool.Adcallback;
|
||||
import com.tool.applockpro.tool.Mytools;
|
||||
import com.tool.applockpro.tool.OkDialogCallback;
|
||||
import com.tool.applockpro.tool.ShowAdDialogCallback;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -41,13 +45,16 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppVH> {
|
||||
private List<ATInterstitial> ads;
|
||||
private int a = 0;
|
||||
|
||||
|
||||
private ShowAdDialogCallback mShowAdDialogCallback;
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
public AppAdapter(Context context, Activity activity) {
|
||||
public AppAdapter(Context context, Activity activity, ShowAdDialogCallback showAdDialogCallback) {
|
||||
ads = ApplockSkin.lodAd();
|
||||
mycontext = context;
|
||||
mactivity = activity;
|
||||
packageManager = context.getPackageManager();
|
||||
|
||||
mShowAdDialogCallback = showAdDialogCallback;
|
||||
a = ApplockSkin.keyad;
|
||||
}
|
||||
|
||||
@ -56,6 +63,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppVH> {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public AppVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
@ -74,75 +82,19 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppVH> {
|
||||
public void onClick(View v) {
|
||||
ApplockSkin.keyad++;
|
||||
if (ApplockSkin.keyad % 5 == 0 || ApplockSkin.keyad == 1) {
|
||||
String msg = updateStatus(holder.switchCompat, mydata, false);
|
||||
showAd(new AdActionListener() {
|
||||
@Override
|
||||
public void onAction() {
|
||||
String strLock = holder.switchCompat.isSelected() ? "unlock" : "lock";
|
||||
new AlertDialog.Builder(mycontext)
|
||||
.setTitle("Tips")
|
||||
.setMessage("Are you sure you want to " + strLock + " " + appname)
|
||||
.setPositiveButton("Sure", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (holder.switchCompat.isSelected()) {
|
||||
holder.switchCompat.setSelected(false);
|
||||
} else {
|
||||
holder.switchCompat.setSelected(true);
|
||||
}
|
||||
Mytools.runIO(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mydata.setLock(holder.switchCompat.isSelected());
|
||||
MyDataBase.getINSTANCE().mydao().update(mydata);
|
||||
|
||||
}
|
||||
});
|
||||
String s;
|
||||
if (holder.switchCompat.isSelected()) {
|
||||
s = String.format(mycontext.getString(R.string.text_locked), appname);
|
||||
} else {
|
||||
s = String.format(mycontext.getString(R.string.text_unlocked), appname);
|
||||
}
|
||||
Toast.makeText(mycontext, s, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
})
|
||||
.show();
|
||||
|
||||
if (mShowAdDialogCallback != null) {
|
||||
mShowAdDialogCallback.onShowAdOkDialog(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
updateStatus(holder.switchCompat, mydata, true);
|
||||
|
||||
if (holder.switchCompat.isSelected()) {
|
||||
holder.switchCompat.setSelected(false);
|
||||
} else {
|
||||
holder.switchCompat.setSelected(true);
|
||||
}
|
||||
Mytools.runIO(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mydata.setLock(holder.switchCompat.isSelected());
|
||||
MyDataBase.getINSTANCE().mydao().update(mydata);
|
||||
|
||||
}
|
||||
});
|
||||
String s;
|
||||
if (holder.switchCompat.isSelected()) {
|
||||
s = String.format(mycontext.getString(R.string.text_locked), appname);
|
||||
} else {
|
||||
s = String.format(mycontext.getString(R.string.text_unlocked), appname);
|
||||
}
|
||||
|
||||
|
||||
Toast.makeText(mycontext, s, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
@ -155,6 +107,29 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppVH> {
|
||||
}
|
||||
}
|
||||
|
||||
private String updateStatus(ImageView imageView, Mydata curData, boolean showToast) {
|
||||
String s;
|
||||
if (imageView.isSelected()) {
|
||||
imageView.setSelected(false);
|
||||
s = String.format(mycontext.getString(R.string.text_locked), curData.getAppName());
|
||||
} else {
|
||||
imageView.setSelected(true);
|
||||
s = String.format(mycontext.getString(R.string.text_unlocked), curData.getAppName());
|
||||
}
|
||||
Mytools.runIO(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
curData.setLock(imageView.isSelected());
|
||||
MyDataBase.getINSTANCE().mydao().update(curData);
|
||||
|
||||
}
|
||||
});
|
||||
if (showToast)
|
||||
Toast.makeText(ApplockSkin.getContext(), s, Toast.LENGTH_SHORT).show();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mydataList.size();
|
||||
|
||||
@ -15,6 +15,7 @@ import com.tool.applockpro.data.Mydao;
|
||||
import com.tool.applockpro.data.Mydata;
|
||||
import com.tool.applockpro.databinding.FragmentAllBinding;
|
||||
import com.tool.applockpro.tool.Mytools;
|
||||
import com.tool.applockpro.tool.ShowAdDialogCallback;
|
||||
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -26,13 +27,20 @@ public class AllFragment extends Fragment {
|
||||
private String tabargs;
|
||||
private AppAdapter thumAdapter;
|
||||
private Mydao mydao;
|
||||
|
||||
private OkDialogFragment okDialogFragment;
|
||||
// private List<Mydata> list1 = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
binding = FragmentAllBinding.inflate(inflater, container, false);
|
||||
thumAdapter = new AppAdapter(requireContext(), requireActivity());
|
||||
thumAdapter = new AppAdapter(requireContext(), requireActivity(), new ShowAdDialogCallback() {
|
||||
@Override
|
||||
public void onShowAdOkDialog(String msg) {
|
||||
showDialog(msg);
|
||||
}
|
||||
});
|
||||
binding.allRv.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
binding.allRv.setAdapter(thumAdapter);
|
||||
mydao = MyDataBase.getINSTANCE().mydao();
|
||||
@ -42,7 +50,14 @@ public class AllFragment extends Fragment {
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void showDialog(String string) {
|
||||
if (okDialogFragment == null) {
|
||||
okDialogFragment = OkDialogFragment.newInstance(string);
|
||||
}else {
|
||||
okDialogFragment.updateContent(string);
|
||||
}
|
||||
okDialogFragment.show(requireActivity().getSupportFragmentManager(), "");
|
||||
}
|
||||
|
||||
public void refesh() {
|
||||
mydao.getAppsBySystem(false).observe(getViewLifecycleOwner(), new Observer<List<Mydata>>() {
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
package com.tool.applockpro.fragment;
|
||||
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.tool.applockpro.R;
|
||||
import com.tool.applockpro.databinding.DialogOkBinding;
|
||||
|
||||
|
||||
public class OkDialogFragment extends DialogFragment {
|
||||
|
||||
|
||||
private DialogOkBinding vb;
|
||||
|
||||
|
||||
private String msgStr;
|
||||
|
||||
|
||||
public OkDialogFragment(String msg) {
|
||||
msgStr = msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
vb = DialogOkBinding.inflate(inflater, container, false);
|
||||
init();
|
||||
return vb.getRoot();
|
||||
}
|
||||
|
||||
public void updateContent(String msg) {
|
||||
msgStr = msg;
|
||||
if (msgStr != null && !msgStr.isEmpty()) {
|
||||
if (vb != null) {
|
||||
vb.textContent.setText(msgStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
Dialog dialog = getDialog();
|
||||
setCancelable(true);
|
||||
if (dialog != null) {
|
||||
Window window = dialog.getWindow();
|
||||
if (window != null) {
|
||||
window.setBackgroundDrawableResource(R.color.transparent);
|
||||
window.getDecorView().setPadding(0, 0, 0, 0);
|
||||
|
||||
WindowManager.LayoutParams attributes = window.getAttributes();
|
||||
attributes.gravity = Gravity.CENTER;
|
||||
attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
attributes.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
window.setAttributes(attributes);
|
||||
}
|
||||
}
|
||||
vb.textContent.setText(msgStr);
|
||||
|
||||
vb.btnOk.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void closeDialog() {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
|
||||
public static OkDialogFragment newInstance(String msg) {
|
||||
|
||||
OkDialogFragment okDialogFragment = new OkDialogFragment(msg);
|
||||
return okDialogFragment;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.tool.applockpro.tool;
|
||||
|
||||
|
||||
import com.anythink.core.api.AdError;
|
||||
|
||||
public interface OkDialogCallback {
|
||||
|
||||
void onClickOk( );
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package com.tool.applockpro.tool;
|
||||
|
||||
|
||||
public interface ShowAdDialogCallback {
|
||||
|
||||
void onShowAdOkDialog(String msg);
|
||||
}
|
||||
8
app/src/main/res/drawable/dialog_bg_white.xml
Normal file
8
app/src/main/res/drawable/dialog_bg_white.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
|
||||
<corners android:radius="24dp" />
|
||||
<solid android:color="@color/white"/>
|
||||
|
||||
</shape>
|
||||
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/activity_web"
|
||||
@ -17,5 +17,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="100dp"
|
||||
android:src="@drawable/im_close"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:id="@+id/close" />
|
||||
</FrameLayout>
|
||||
</RelativeLayout>
|
||||
71
app/src/main/res/layout/dialog_ok.xml
Normal file
71
app/src/main/res/layout/dialog_ok.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/activity_Permission"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:context=".activity.PermissionActivity">
|
||||
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/cons_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/im"
|
||||
android:layout_marginStart="40dp"
|
||||
android:layout_marginTop="-30dp"
|
||||
android:layout_marginEnd="40dp"
|
||||
android:background="@drawable/dialog_bg_white"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp"
|
||||
android:paddingBottom="32dp">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="45dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:gravity="center"
|
||||
android:lineSpacingExtra="3dp"
|
||||
android:text="@string/ok_dialog_msg"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_ok"
|
||||
android:layout_width="98dp"
|
||||
android:layout_height="44dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginTop="25dp"
|
||||
android:background="@drawable/step_uncheck"
|
||||
android:gravity="center"
|
||||
android:text="@string/ok"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_content" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/im"
|
||||
android:layout_width="230dp"
|
||||
android:layout_height="150dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:src="@mipmap/image_permission" />
|
||||
</RelativeLayout>
|
||||
</FrameLayout>
|
||||
@ -18,5 +18,5 @@
|
||||
<color name="oval_bg_color">#33FFFFFF</color>
|
||||
<color name="text_color">#3A3938</color>
|
||||
<color name="item_lock_bg_color">#80FFFFFF</color>
|
||||
|
||||
<color name="transparent">#00000000</color>
|
||||
</resources>
|
||||
@ -5,8 +5,8 @@
|
||||
<string name="step2">Step 2</string>
|
||||
<string name="change_pwd">Change password</string>
|
||||
<string name="Privacy">Privacy Policy</string>
|
||||
<string name="text_locked">locked: %s</string>
|
||||
<string name="text_unlocked">Unlocked: %s</string>
|
||||
<string name="text_locked">locked %s Success</string>
|
||||
<string name="text_unlocked">Unlocked %s Success</string>
|
||||
<string name="text_continue">Continue</string>
|
||||
<string name="nolock_tips">At present, there is nothing\n application are locked</string>
|
||||
<string name="lock_tpis">Set Passcode</string>
|
||||
@ -26,4 +26,7 @@
|
||||
<string name="version_text">Version</string>
|
||||
<string name="share_title">Here is a Lock App</string>
|
||||
<string name="lock_re_enter">Please re-enter the 4-digit \n password you just created</string>
|
||||
<string name="ok_dialog_msg">Are you sure you want to %s %S</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="ok">Ok</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user