Skip to content

Commit

Permalink
以图搜源的提示增加一个不再提示的按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
duzhaokun123 committed Mar 22, 2020
1 parent 8c581fc commit 06a8011
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 34 additions & 19 deletions app/src/main/java/ceui/lisa/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

Expand Down Expand Up @@ -215,28 +217,41 @@ public boolean onNavigationItemSelected(MenuItem item) {
intent.putExtra(Params.USER_ID, sUserModel.getResponse().getUser().getId());
break;
case R.id.nav_reverse:
// TODO: 20-3-16 国际化 仅第一次时显示 向用户索要权限
new AlertDialog.Builder(MainActivity.this)
.setTitle("关于以图搜源")
.setMessage("以图搜源的实质是将你选择的图片上传至 https://saucenao.com/ 进行搜索\n" +
"https://saucenao.com/ 可以算一个专门查找P站图的网站,更多信息不在这里介绍\n" +
"注意:该功能需要 READ_EXTERNAL_STORAGE 以读取图片,如果 SDK >= 23 且没有授权" +
"则功能无法实现")
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String[] permissions = new String[] {Manifest.permission.READ_EXTERNAL_STORAGE};
int i = ContextCompat.checkSelfPermission(this, permissions[0]);
if (i != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, permissions, 1);
// TODO: 20-3-16 国际化 向用户索要权限
if (Shaft.sSettings.isReverseDialogNeverShowAgain()) {
gotoReverse();
} else {
CheckBox checkBox = new CheckBox(this);
checkBox.setText(R.string.never_show_again);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Shaft.sSettings.setReverseDialogNeverShowAgain(isChecked);
}
});
new AlertDialog.Builder(MainActivity.this)
.setTitle("关于以图搜源")
.setMessage("以图搜源的实质是将你选择的图片上传至 https://saucenao.com/ 进行搜索\n" +
"https://saucenao.com/ 可以算一个专门查找P站图的网站,更多信息不在这里介绍\n" +
"注意:该功能需要 READ_EXTERNAL_STORAGE 以读取图片,如果 SDK >= 23 且没有授权" +
"则功能无法实现")
.setView(checkBox)
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String[] permissions = new String[] {Manifest.permission.READ_EXTERNAL_STORAGE};
int i = ContextCompat.checkSelfPermission(this, permissions[0]);
if (i != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, permissions, 1);
} else {
gotoReverse();
}
} else {
gotoReverse();
}
} else {
gotoReverse();
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
break;
case R.id.nav_send:
intent = new Intent(mContext, TemplateActivity.class);
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/ceui/lisa/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class Settings {

private String webDownloadPath = "";

private boolean reverseDialogNeverShowAgain = false;

public String getAppLanguage() {
if(!TextUtils.isEmpty(appLanguage)){
return appLanguage;
Expand Down Expand Up @@ -278,4 +280,12 @@ public boolean isShowPixivDialog() {
public void setShowPixivDialog(boolean showPixivDialog) {
this.showPixivDialog = showPixivDialog;
}

public boolean isReverseDialogNeverShowAgain() {
return reverseDialogNeverShowAgain;
}

public void setReverseDialogNeverShowAgain(boolean reverseDialogNeverShowAgain) {
this.reverseDialogNeverShowAgain = reverseDialogNeverShowAgain;
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,7 @@
<string name="r_eighteen">R</string>
<string name="ranking_list">Ranking List</string>
<string name="recmd_for_you">Recommend for you</string>
<string name="save">save</string>
<string name="shoud_not_be_empty">shoud not be empty</string>
<string name="never_show_again">never show again</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<string name="recmd_for_you">为你推荐</string>
<string name="email_address">邮箱地址</string>
<string name="operate_success">操作成功</string>
<string name="save">save</string>
<string name="save">保存</string>
<string name="shoud_not_be_empty">不应为空</string>
<string name="never_show_again">不再显示</string>
</resources>

0 comments on commit 06a8011

Please sign in to comment.