Skip to content

Commit 6c89465

Browse files
author
qwe7002
committed
Merge branch 'develop' into 'master'
添加自动检测标题功能 See merge request SilverBlog/SilverBlog_Android!83
2 parents cce91c0 + 005fc0c commit 6c89465

File tree

20 files changed

+573
-472
lines changed

20 files changed

+573
-472
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ build:
2323
image: preventis/docker-android-alpine:latest
2424
stage: build
2525
script:
26-
- echo -e "ext {\n appVersionCode = ${CI_PIPELINE_ID}\n appVersionName = \"_${CI_JOB_ID}\"}" > ./app/version.gradle
26+
- echo -e "ext {\n appVersionCode = ${CI_PIPELINE_ID}\n appVersionName = \"${CI_COMMIT_REF_NAME}\"}" > ./app/version.gradle
2727
- echo -e "systemProp.http.nonProxyHosts=dl.google.com\n systemProp.http.proxyHost=192.168.3.8\n systemProp.http.proxyPort=1080\n systemProp.https.proxyHost=192.168.3.8\n systemProp.https.proxyPort=1080\n org.gradle.jvmargs=-Xmx1536m\n org.gradle.parallel=true" >> gradle.properties
2828
- export GRADLE_USER_HOME=$(pwd)/.gradle
2929
- chmod +x ./gradlew

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ android {
55
buildToolsVersion '28.0.1'
66
defaultConfig {
77
applicationId 'org.SilverBlog.client'
8-
minSdkVersion 21
8+
minSdkVersion 23
99
targetSdkVersion 28
10-
versionCode appVersionCode
1110
versionName appVersionName
11+
versionCode appVersionCode
1212
}
1313
signingConfigs {
1414
releaseConfig {

app/src/main/java/org/SilverBlog/client/RecyclerViewAdapter.java

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.content.DialogInterface;
77
import android.content.Intent;
88
import android.content.SharedPreferences;
9-
import android.os.AsyncTask;
109
import android.support.annotation.NonNull;
1110
import android.support.v4.content.LocalBroadcastManager;
1211
import android.support.v7.app.AlertDialog;
@@ -20,19 +19,26 @@
2019
import com.google.gson.JsonObject;
2120
import com.google.gson.JsonParser;
2221

22+
import java.io.IOException;
2323
import java.util.List;
24+
import java.util.Objects;
25+
26+
import okhttp3.Call;
27+
import okhttp3.Callback;
28+
import okhttp3.OkHttpClient;
29+
import okhttp3.Request;
30+
import okhttp3.RequestBody;
31+
import okhttp3.Response;
2432

2533
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.NewsViewHolder> {
2634

27-
private static final String MY_BROADCAST_TAG = "com.reallct.qwe7002.smartblog_client";
2835
static SharedPreferences sharedPreferences;
2936
private List<Post_List_Serialzable> post_list_serialzables;
3037
private Context context;
3138

32-
public RecyclerViewAdapter(List<Post_List_Serialzable> post_list_serialzables, Context context) {
39+
RecyclerViewAdapter(List<Post_List_Serialzable> post_list_serialzables, Context context) {
3340
this.post_list_serialzables = post_list_serialzables;
3441
this.context = context;
35-
3642
}
3743

3844
@NonNull
@@ -69,9 +75,46 @@ public void onClick(DialogInterface dialogInterface, int i) {
6975
new DialogInterface.OnClickListener() {
7076
@Override
7177
public void onClick(DialogInterface dialogInterface, int i) {
78+
final ProgressDialog mpDialog = new ProgressDialog(context);
79+
mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
80+
mpDialog.setTitle(context.getString(R.string.loading));
81+
mpDialog.setMessage(context.getString(R.string.loading_message));
82+
mpDialog.setIndeterminate(false);
83+
mpDialog.setCancelable(false);
84+
mpDialog.show();
7285
JsonObject postobj = public_value.post_list.get(position).getAsJsonObject();
7386
String title = postobj.get("title").getAsString();
74-
new delete_post().execute(Integer.toString(position), title);
87+
RequestBody body = RequestBody.create(public_value.JSON, "{\"post_id\":" + Integer.toString(position) + ",\"sign\":\"" + public_func.getMD5(Integer.toString(position) + title + public_value.password) + "\"}");
88+
Request request = new Request.Builder().url("https://" + public_value.host + "/control/delete").method("POST", body).build();
89+
OkHttpClient okHttpClient = new OkHttpClient();
90+
Call call = okHttpClient.newCall(request);
91+
call.enqueue(new Callback() {
92+
@Override
93+
public void onFailure(Call call, IOException e) {
94+
mpDialog.cancel();
95+
Intent intent = new Intent();
96+
intent.putExtra("result", context.getString(R.string.submit_error));
97+
intent.putExtra("success", false);
98+
intent.setAction(public_value.MY_BROADCAST_TAG);
99+
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
100+
}
101+
102+
@Override
103+
public void onResponse(Call call, Response response) throws IOException {
104+
mpDialog.cancel();
105+
JsonParser parser = new JsonParser();
106+
final JsonObject objects = parser.parse(Objects.requireNonNull(response.body()).string()).getAsJsonObject();
107+
String result_message = context.getString(R.string.submit_error);
108+
if (objects.get("status").getAsBoolean()) {
109+
result_message = context.getString(R.string.submit_success);
110+
}
111+
Intent intent = new Intent();
112+
intent.putExtra("result", result_message);
113+
intent.putExtra("success", true);
114+
intent.setAction(public_value.MY_BROADCAST_TAG);
115+
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
116+
}
117+
});
75118
}
76119
}).setNegativeButton(R.string.cancel, null).show();
77120
break;
@@ -88,56 +131,16 @@ public int getItemCount() {
88131
return post_list_serialzables.size();
89132
}
90133

91-
//自定义ViewHolder类
92134
static class NewsViewHolder extends RecyclerView.ViewHolder {
93135

94136
CardView cardView = (CardView) itemView.findViewById(R.id.card_view);
95137
TextView title = (TextView) itemView.findViewById(R.id.title);
96138
TextView excerpt = (TextView) itemView.findViewById(R.id.excerpt);
97139

98-
public NewsViewHolder(final View itemView) {
140+
NewsViewHolder(final View itemView) {
99141
super(itemView);
100-
//设置TextView背景为半透明
101-
//news_title.setBackgroundColor(Color.argb(20, 0, 0, 0));
102142
}
103143

104144

105145
}
106-
107-
@SuppressLint("StaticFieldLeak")
108-
private class delete_post extends AsyncTask<String, Integer, String> {
109-
ProgressDialog mpDialog = new ProgressDialog(context);
110-
111-
@Override
112-
protected void onPreExecute() {
113-
mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
114-
mpDialog.setTitle(context.getString(R.string.loading));
115-
mpDialog.setMessage(context.getString(R.string.loading_message));
116-
mpDialog.setIndeterminate(false);
117-
mpDialog.setCancelable(false);
118-
mpDialog.show();
119-
}
120-
121-
@Override
122-
protected String doInBackground(String... args) {
123-
124-
return request.send_request("{\"post_id\":" + args[0] + ",\"sign\":\"" + request.getMD5(args[0] + args[1] + public_value.password) + "\"}", "delete");
125-
}
126-
127-
@Override
128-
protected void onPostExecute(String result) {
129-
mpDialog.cancel();
130-
JsonParser parser = new JsonParser();
131-
final JsonObject objects = parser.parse(result).getAsJsonObject();
132-
String result_message = context.getString(R.string.submit_error);
133-
if (objects.get("status").getAsBoolean()) {
134-
result_message = context.getString(R.string.submit_success);
135-
}
136-
Intent intent = new Intent();
137-
intent.putExtra("result", result_message);
138-
intent.putExtra("success", true);
139-
intent.setAction(MY_BROADCAST_TAG);
140-
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
141-
}
142-
}
143146
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.SilverBlog.client;
2+
3+
class content_json {
4+
private int post_id;
5+
private String content;
6+
private String sign;
7+
private String title;
8+
private String name;
9+
10+
void setName(String name) {
11+
this.name = name;
12+
}
13+
14+
void setPost_id(int post_id) {
15+
this.post_id = post_id;
16+
}
17+
18+
void setTitle(String title) {
19+
this.title = title;
20+
}
21+
22+
void setContent(String Content) {
23+
this.content = Content;
24+
}
25+
26+
void setsign(String sign) {
27+
this.sign = sign;
28+
}
29+
}

app/src/main/java/org/SilverBlog/client/main_Activity.java

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.Manifest;
44
import android.annotation.SuppressLint;
5+
import android.app.ProgressDialog;
56
import android.content.Context;
67
import android.content.DialogInterface;
78
import android.content.Intent;
@@ -28,9 +29,16 @@
2829
import com.google.gson.JsonParser;
2930
import com.google.zxing.activity.CaptureActivity;
3031

32+
import java.io.IOException;
3133
import java.util.ArrayList;
3234
import java.util.Map;
3335

36+
import okhttp3.Call;
37+
import okhttp3.Callback;
38+
import okhttp3.OkHttpClient;
39+
import okhttp3.Request;
40+
import okhttp3.Response;
41+
3442

3543
public class main_Activity extends AppCompatActivity {
3644
SharedPreferences sharedPreferences;
@@ -40,6 +48,7 @@ public class main_Activity extends AppCompatActivity {
4048
EditText password;
4149
JsonObject host_list;
4250
ArrayList<String> host_name_list;
51+
4352
@Override
4453
public boolean onCreateOptionsMenu(Menu menu) {
4554
getMenuInflater().inflate(R.menu.main_toolbar_menu, menu);
@@ -89,7 +98,16 @@ public void onClick(DialogInterface dialogInterface, int i) {
8998
start_edit();
9099

91100
}
92-
}).show();
101+
}).setNegativeButton(R.string.clean, new DialogInterface.OnClickListener() {
102+
@Override
103+
public void onClick(DialogInterface dialogInterface, int i) {
104+
SharedPreferences.Editor editor = sharedPreferences.edit();
105+
editor.remove("host_list");
106+
editor.apply();
107+
host_list = new JsonParser().parse("{}").getAsJsonObject();
108+
host_name_list = new ArrayList<>();
109+
}
110+
}).setPositiveButton(R.string.cancel, null).show();
93111
}
94112
}
95113
);
@@ -99,7 +117,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
99117
final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
100118
save_button.setOnClickListener(new View.OnClickListener() {
101119
@Override
102-
public void onClick(View view) {
120+
public void onClick(final View view) {
103121
if (getCurrentFocus() != null && getCurrentFocus().getWindowToken() != null) {
104122
if (manager != null) {
105123
manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
@@ -110,17 +128,49 @@ public void onClick(View view) {
110128
.setAction("Action", null).show();
111129
return;
112130
}
131+
113132
host_save = String.valueOf(host.getText());
114-
password_save = request.getMD5(String.valueOf(password.getText()));
115-
SharedPreferences.Editor editor = sharedPreferences.edit();
116-
if (!host_list.has(host_save)) {
117-
host_list.add(host_save, new JsonParser().parse("{\"host\":\"" + host_save + "\",\"password\":\"" + password_save + "\"}"));
118-
}
119-
editor.putString("host_list", new Gson().toJson(host_list));
120-
editor.putString("host", host_save);
121-
editor.putString("password", password_save);
122-
editor.apply();
123-
start_edit();
133+
password_save = public_func.getMD5(String.valueOf(password.getText()));
134+
final ProgressDialog mpDialog = new ProgressDialog(main_Activity.this);
135+
mpDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
136+
mpDialog.setTitle(getString(R.string.loading));
137+
mpDialog.setMessage(getString(R.string.loading_message));
138+
mpDialog.setIndeterminate(false);
139+
mpDialog.setCancelable(false);
140+
mpDialog.show();
141+
OkHttpClient okHttpClient = new OkHttpClient();
142+
Request request = new Request.Builder().url("https://" + host_save + "/control").method("OPTIONS", null).build();
143+
Call call = okHttpClient.newCall(request);
144+
call.enqueue(new Callback() {
145+
@Override
146+
public void onFailure(Call call, IOException e) {
147+
mpDialog.cancel();
148+
Snackbar.make(view, R.string.cannot_connect, Snackbar.LENGTH_LONG)
149+
.setAction("Action", null).show();
150+
}
151+
152+
@Override
153+
public void onResponse(Call call, Response response) {
154+
mpDialog.cancel();
155+
if (response.code() != 204) {
156+
Snackbar.make(view, R.string.cannot_connect, Snackbar.LENGTH_LONG)
157+
.setAction("Action", null).show();
158+
return;
159+
}
160+
SharedPreferences.Editor editor = sharedPreferences.edit();
161+
if (!host_list.has(host_save)) {
162+
host_list.add(host_save, new JsonParser().parse("{\"host\":\"" + host_save + "\",\"password\":\"" + password_save + "\"}"));
163+
}
164+
editor.putString("host_list", new Gson().toJson(host_list));
165+
editor.putString("host", host_save);
166+
editor.putString("password", password_save);
167+
editor.apply();
168+
start_edit();
169+
170+
}
171+
});
172+
173+
124174

125175
}
126176
});
@@ -136,14 +186,14 @@ void start_edit() {
136186

137187
@Override
138188
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
139-
if(requestCode ==1){
140-
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
141-
Intent intent = new Intent(main_Activity.this, CaptureActivity.class);
142-
startActivityForResult(intent, 0);
143-
return;
144-
}
145-
Snackbar.make(host, R.string.scan_qr, Snackbar.LENGTH_LONG)
146-
.setAction("Action", null).show();
189+
if (requestCode == 1) {
190+
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
191+
Intent intent = new Intent(main_Activity.this, CaptureActivity.class);
192+
startActivityForResult(intent, 0);
193+
return;
194+
}
195+
Snackbar.make(host, R.string.scan_qr, Snackbar.LENGTH_LONG)
196+
.setAction("Action", null).show();
147197
}
148198
}
149199

0 commit comments

Comments
 (0)