Skip to content

Commit

Permalink
添加帮助文档,修改最低SDK至21
Browse files Browse the repository at this point in the history
  • Loading branch information
xz-dev committed May 6, 2019
1 parent 6303762 commit aa019cb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 24 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "net.xzos.upgradeall"
minSdkVersion 26
minSdkVersion 21
targetSdkVersion 28
versionCode 5
versionName "0.0.4"
versionCode 6
versionName "0.0.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/net/xzos/UpgradeAll/HttpApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ private void flashData() throws JSONException {
String jsonText = getHttpResponse(api_url);
if (jsonText.length() != 0) {
this.returnJsonArray = new JSONArray(jsonText);
Log.d(TAG, "getRelease: returnJsonArray: " + returnJsonArray);
}
}
}

private JSONObject getRelease(int releaseNum) {
Log.d(TAG, "getRelease: returnJsonArray: " + returnJsonArray);
JSONObject jsonObject = new JSONObject();
try {
jsonObject = new JSONObject(this.returnJsonArray.getString(releaseNum));
Expand Down
19 changes: 16 additions & 3 deletions app/src/main/java/net/xzos/UpgradeAll/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.xzos.UpgradeAll;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -19,7 +20,7 @@
import java.util.List;

public class MainActivity extends AppCompatActivity {
private List<upgradeCard> upgradeCardList = new ArrayList<>();
private List<UpgradeCard> upgradeCardList = new ArrayList<>();
private UpgradeItemCardAdapter adapter;

private RecyclerView recyclerView;
Expand All @@ -39,6 +40,18 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
case R.id.app_help:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://xzos.net/upgradeall-readme/"));
intent = Intent.createChooser(intent, "请选择浏览器");
startActivity(intent);
return true;
default:
return false;
}
});
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(view -> {
Intent intent = new Intent(MainActivity.this, UpgradeItemSettingActivity.class);
Expand Down Expand Up @@ -78,7 +91,7 @@ private void refreshCardView() {
String url = upgradeItem.getUrl();
String latestVersion = updater.getLatestVersion(databaseId);
String installedVersion = updater.getInstalledVersion(databaseId);
upgradeCardList.add(new upgradeCard(databaseId, name, installedVersion + " -> " + latestVersion, url, api));
upgradeCardList.add(new UpgradeCard(databaseId, name, installedVersion + " -> " + latestVersion, url, api));
}
setRecyclerView();
}
Expand Down Expand Up @@ -110,7 +123,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
if (id == R.id.app_help) {
return true;
}
return super.onOptionsItemSelected(item);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.xzos.UpgradeAll;

public class upgradeCard {
public class UpgradeCard {
private int databaseId;
private String name;
private String version;
private String url;
private String api;

upgradeCard(int databaseId, String name, String version, String url, String api) {
UpgradeCard(int databaseId, String name, String version, String url, String api) {
this.databaseId = databaseId;
this.name = name;
this.version = version;
Expand Down
20 changes: 7 additions & 13 deletions app/src/main/java/net/xzos/UpgradeAll/UpgradeItemCardAdapter.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package net.xzos.UpgradeAll;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
Expand All @@ -28,10 +25,9 @@

public class UpgradeItemCardAdapter extends RecyclerView.Adapter<UpgradeItemCardAdapter.ViewHolder> {

private static final String TAG = "UpgradeItemCardAdapter";
private List<upgradeCard> mUpgradeList;
private List<UpgradeCard> mUpgradeList;

UpgradeItemCardAdapter(List<upgradeCard> upgradeList) {
UpgradeItemCardAdapter(List<UpgradeCard> upgradeList) {
mUpgradeList = upgradeList;
}

Expand Down Expand Up @@ -63,10 +59,9 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_upgrade, parent, false));
}

@SuppressLint("ShowToast")
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
upgradeCard upgradeCard = mUpgradeList.get(position);
UpgradeCard upgradeCard = mUpgradeList.get(position);
holder.name.setText(upgradeCard.getName());
holder.version.setText(upgradeCard.getVersion());
holder.api.setText(upgradeCard.getApi());
Expand All @@ -80,10 +75,7 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
String key = sIterator.next();
itemList.add(key);
}
String[] itemStringArray = new String[itemList.size()];
for (int i = 0; i < itemList.size(); i++) {
itemStringArray[i] = itemList.get(i);
}
String[] itemStringArray=itemList.toArray(new String[0]);
// 获取文件列表

AlertDialog.Builder builder = new AlertDialog.Builder(holder.version.getContext());
Expand Down Expand Up @@ -115,10 +107,12 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
// 删除数据库
String api_url = GithubApi.getApiUrl(holder.url.getText().toString())[0];
LitePal.deleteAll(RepoDatabase.class, "api_url = ?", api_url);
Toast.makeText(MyApplication.getContext(), String.format("%s已删除", api_url), Toast.LENGTH_LONG);
// 删除指定数据库
Intent intent = new Intent(holder.del_button.getContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
MyApplication.getContext().startActivity(intent);
// 重新跳转刷新界面
// TODO: 需要优化刷新方法
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="net.xzos.UpgradeAll.MainActivity">
<item
android:id="@+id/action_settings"
android:id="@+id/app_help"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never" />
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources>
<string name="app_name">UpgradeAll</string>
<string name="action_settings">Settings</string>
<string name="action_settings">帮助</string>
<string name="title_activity_update_item_settings">Settings</string>
<!-- support api -->
<string-array name="http_support_api">
Expand All @@ -15,9 +15,12 @@
<item>
Magisk 模块
</item>
<!--
TODO
<item>
自定义 Shell 命令
</item>
-->
</string-array>

<string name="upgrade_item_setting_add_button">添加</string>
Expand Down

0 comments on commit aa019cb

Please sign in to comment.