Skip to content

Commit

Permalink
commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Spaso1 committed Oct 1, 2024
1 parent 4c52cde commit 2868069
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdk 30
targetSdk 33
versionCode 1
versionName "1.01.4"
versionName "1.01.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
// 自定义打包名称
Expand Down
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.01.4",
"outputFile": "AstralCloud_release_v1.01.4.apk"
"versionName": "1.01.5",
"outputFile": "AstralCloud_release_v1.01.5.apk"
}
],
"elementType": "File"
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/example/astralcloud/DownActi.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public class DownActi extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.download_item);
sharedPreferences = getSharedPreferences("MyPrefs", MODE_PRIVATE);
editor = sharedPreferences.edit();

}
}
41 changes: 38 additions & 3 deletions app/src/main/java/com/example/astralcloud/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public void onClick(android.view.View v) {
}
});

SharedPreferences sharedPreferences = getSharedPreferences("Download", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
SharedPreferences.OnSharedPreferenceChangeListener listener = (prefs, key) -> {
Log.d("TAG", "Preference changed: " + key);
};
sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
/**
* 以上是按钮和页面部分
* 下方是 webview 部分
Expand Down Expand Up @@ -315,7 +321,8 @@ public void onDownloadStart(String url, String userAgent, String contentDisposit
.setMessage("你即将下载: " + contentDisposition)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
new MuDownloadTask().execute(url, contentDisposition);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
Expand Down Expand Up @@ -361,7 +368,18 @@ public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(MainActivity.this,MainActivity.class);
startActivity(intent);
}else{
webView.loadUrl(ip);
Intent intent = getIntent();
try {
if(!(intent.getStringExtra("cloudreveip").equals("no"))) {
webView.loadUrl(intent.getStringExtra("cloudreveip"));
}else {
}
}catch (Exception e) {
webView.loadUrl(ip);


}

}

// 检查是否有权限
Expand All @@ -381,6 +399,20 @@ public void onClick(DialogInterface dialog, int id) {
startActivityForResult(intent, 1);
}
}
Button button = findViewById(R.id.a1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Sec.class);
SharedPreferences sharedPreferences = getSharedPreferences("data", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("cloudreveip", webView.getUrl());
editor.commit();
Log.d("cloudreveip", cloudreveip);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
});
}

@Override
Expand Down Expand Up @@ -519,11 +551,12 @@ private String parseFileName(String contentDisposition) {
return null;
}
private class DownloadTask extends AsyncTask<String, Void, String> {
private String filename;
@Override
protected String doInBackground(String... params) {
String url = params[0];
String contentDisposition = params[1];

this.filename = filename;
// 解析文件名
String fileName = parseFileName(contentDisposition);
if (fileName == null || fileName.isEmpty()) {
Expand Down Expand Up @@ -582,7 +615,9 @@ private void download(String url, String outputPath) {
connection.disconnect();
}
}

}

}
private class MuDownloadTask extends AsyncTask<String, Integer, String> {
private static final int THREAD_COUNT = 4; // 可以调整线程数量
Expand Down
25 changes: 22 additions & 3 deletions app/src/main/java/com/example/astralcloud/Sec.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.example.astralcloud;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.provider.DocumentsContract;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;
Expand All @@ -14,26 +18,41 @@
import java.nio.charset.StandardCharsets;

public class Sec extends AppCompatActivity {
public static final String ACTION_OPEN_DOCUMENT = "android.intent.action.OPEN_DOCUMENT";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Context context = this;
setContentView(R.layout.setting_set);
Button Back2button = findViewById(R.id.button_backing);
Back2button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
Intent intent = new Intent(Sec.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
SharedPreferences sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
String cloud = sharedPreferences.getString("cloudreveip", "no");
intent.putExtra("cloudreveip", cloud);
editor.clear();
editor.commit();
startActivity(intent);
}
});
Button xiazai = findViewById(R.id.xiazai);
xiazai.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
Intent intent = new Intent(Sec.this, DownActi.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
String path = "%2fDownload%2f";
Uri uri = Uri.parse("content://com.android.externalstorage.documents/document/primary:" + path);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");//想要展示的文件类型
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri);
startActivityForResult(intent, 0);


startActivity(intent);
}
});
secCreate();
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:layout_anchorGravity="bottom|center"
app:layout_anchor="@+id/webview" android:id="@+id/button2"/>
<Button
android:text="+"
android:textSize="10dp"
android:layout_marginLeft="40dp"
android:layout_marginBottom="60dp"
android:layout_width="29dp"
android:layout_height="29dp" app:layout_anchorGravity="start|bottom"
app:layout_anchor="@+id/webview"
android:id="@+id/a1"
android:background="@drawable/round_button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
<Button
android:text="返回"
android:layout_marginLeft="40dp"
Expand Down

0 comments on commit 2868069

Please sign in to comment.