Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
- [fix] Image preview
- [fix] Album backup
- other bugs
  • Loading branch information
zhwanng committed Oct 30, 2024
1 parent ae12e44 commit 1261f95
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* It sends back to the Authenticator the result.
*/
public class SeafileAuthenticatorActivity extends BaseAuthenticatorActivity {
public static final String SINGLE_SIGN_ON_SERVER_URL = "single sign on server url";

public static final int SEACLOUD_CC = 0;
public static final int SINGLE_SIGN_ON_LOGIN = 1;
Expand Down Expand Up @@ -127,7 +128,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
Account account = new Account(getIntent().getStringExtra(SeafileAuthenticatorActivity.ARG_ACCOUNT_NAME), Constants.Account.ACCOUNT_TYPE);

String serverUrl = SupportAccountManager.getInstance().getUserData(account, Authenticator.KEY_SERVER_URI);
intent.putExtra(SingleSignOnActivity.SINGLE_SIGN_ON_SERVER_URL, serverUrl);
intent.putExtra(SeafileAuthenticatorActivity.SINGLE_SIGN_ON_SERVER_URL, serverUrl);
if (getIntent() != null) {
intent.putExtras(getIntent().getExtras());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.widget.Toolbar;

import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.blankj.utilcode.util.RegexUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.ui.base.BaseActivity;

import java.util.Locale;

/**
* Single Sign-On welcome page
* <p/>
*/
public class SingleSignOnActivity extends BaseActivity implements Toolbar.OnMenuItemClickListener {
public static final String DEBUG_TAG = SingleSignOnActivity.class.getSimpleName();
public static final String DEBUG_TAG = "SingleSignOnActivity";

public static final String SINGLE_SIGN_ON_SERVER_URL = "single sign on server url";
public static final String SINGLE_SIGN_ON_HTTPS_PREFIX = "https://";

private Button mNextBtn;
Expand All @@ -44,8 +49,9 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
String url = getServerUrl();
if (isServerUrlValid(url))
if (isServerUrlValid(url)) {
openAuthorizePage(url);
}
}
});

Expand All @@ -56,7 +62,7 @@ public void onClick(View v) {
getSupportActionBar().setTitle(R.string.shib_login_title);
}

@Override
@Override
public boolean onMenuItemClick(MenuItem item) {
return super.onOptionsItemSelected(item);
}
Expand All @@ -72,7 +78,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private boolean isServerUrlValid(String serverUrl) {
if (serverUrl == null || serverUrl.isEmpty()) {
if (TextUtils.isEmpty(serverUrl)) {
ToastUtils.showLong(R.string.shib_server_url_empty);
return false;
}
Expand All @@ -82,6 +88,14 @@ private boolean isServerUrlValid(String serverUrl) {
return false;
}

String serverUrl1 = serverUrl
.toLowerCase(Locale.ROOT)
.replace("https://", "")
.replace("http://", "");
if (TextUtils.isEmpty(serverUrl1)) {
return false;
}

return true;
}

Expand All @@ -91,8 +105,8 @@ private String getServerUrl() {
}

private void openAuthorizePage(String serverUrl) {
Intent intent = new Intent(SingleSignOnActivity.this, SingleSignOnAuthorizeActivity.class);
intent.putExtra(SINGLE_SIGN_ON_SERVER_URL, serverUrl);
Intent intent = new Intent(this, SingleSignOnAuthorizeActivity.class);
intent.putExtra(SeafileAuthenticatorActivity.SINGLE_SIGN_ON_SERVER_URL, serverUrl);
intent.putExtras(getIntent());
startActivityForResult(intent, SINGLE_SIGN_ON_AUTH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;

import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.Observer;

import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.view.MenuItem;
Expand All @@ -26,26 +21,21 @@
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.Observer;

import com.blankj.utilcode.util.ToastUtils;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeadroidApplication;
import com.seafile.seadroid2.SeafException;
import com.seafile.seadroid2.account.Account;
import com.seafile.seadroid2.account.AccountInfo;
import com.seafile.seadroid2.framework.datastore.DataManager;
import com.seafile.seadroid2.framework.util.DeviceIdManager;
import com.seafile.seadroid2.framework.util.Utils;
import com.seafile.seadroid2.ssl.CertsManager;
import com.seafile.seadroid2.ui.base.BaseActivity;
import com.seafile.seadroid2.ui.base.BaseActivityWithVM;
import com.seafile.seadroid2.ui.dialog.SslConfirmDialog;
import com.seafile.seadroid2.framework.util.ConcurrentAsyncTask;
import com.seafile.seadroid2.framework.util.DeviceIdManager;
import com.seafile.seadroid2.framework.util.Utils;

import org.json.JSONException;

import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -87,13 +77,17 @@ protected void onCreate(Bundle savedInstanceState) {

initViewModel();

String url = getIntent().getStringExtra(SingleSignOnActivity.SINGLE_SIGN_ON_SERVER_URL);
String url = getIntent().getStringExtra(SeafileAuthenticatorActivity.SINGLE_SIGN_ON_SERVER_URL);
CookieManager.getInstance().removeAllCookie();
openAuthorizePage(url);
}

private void openAuthorizePage(String url) {
Log.d(DEBUG_TAG, "server url is " + url);
if (TextUtils.isEmpty(url)) {
ToastUtils.showLong(R.string.err_server_andress_empty);
return;
}

serverUrl = url;

Expand Down Expand Up @@ -266,7 +260,7 @@ public void onRejected() {
dialog.show(getSupportFragmentManager(), SslConfirmDialog.FRAGMENT_TAG);
}
}

@Override
public void onPageFinished(WebView webView, String url) {
Log.d(DEBUG_TAG, "onPageFinished " + serverUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ private void checkLastPosition(int position) {
}

private void saveSettings() {
//TODO improve
SystemSwitchUtils.getInstance(this).syncSwitchUtils();

for (Fragment fragment : fragmentList) {
if (fragment instanceof HowToUploadFragment howToUploadFragment) {
Expand Down Expand Up @@ -163,6 +161,10 @@ private void saveSettings() {
}
}

//TODO improve
// CameraUploadManager.getInstance().setCameraAccount(mAccount);
SystemSwitchUtils.getInstance(this).syncSwitchUtils();

Intent intent = new Intent();
intent.putExtra(CAMERA_UPLOAD_REMOTE_LIBRARY, isChooseRepoPage);
intent.putExtra(CAMERA_UPLOAD_LOCAL_DIRECTORIES, isChooseDirPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.widget.EditText;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;

import com.blankj.utilcode.util.ToastUtils;
Expand All @@ -19,19 +20,29 @@ public class NewDirFileDialogFragment extends RequestCustomDialogFragmentWithVM<
private String parentDir, repoId;
private boolean isDir;

public static NewDirFileDialogFragment newInstance() {

public static NewDirFileDialogFragment newInstance(String repoId, String parentDir, boolean isDir) {
Bundle args = new Bundle();

args.putString("repo_id", repoId);
args.putString("parent_dir", parentDir);
args.putBoolean("is_dir", isDir);
NewDirFileDialogFragment fragment = new NewDirFileDialogFragment();
fragment.setArguments(args);
return fragment;
}

public void initData(String repoId, String parentDir, boolean isDir) {
this.repoId = repoId;
this.parentDir = parentDir;
this.isDir = isDir;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle args = getArguments();
if (args == null) {
return;
}

repoId = args.getString("repo_id");
parentDir = args.getString("parent_dir");
isDir = args.getBoolean("is_dir");

}

@Override
Expand Down Expand Up @@ -63,7 +74,7 @@ protected void onPositiveClick() {
@Override
protected void initView(LinearLayout containerView) {
super.initView(containerView);

if (TextUtils.isEmpty(parentDir)) {
throw new IllegalArgumentException("this dialogFragment need parentDir param");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ protected void onCreate(Bundle savedInstanceState) {
action = intent.getStringExtra("action");
direntModel = intent.getParcelableExtra("dirent");
if (null == direntModel) {
throw new IllegalArgumentException("missing args");
throw new IllegalArgumentException("missing dirent args");
}

repoId = direntModel.repo_id;

destinationFile = getLocalDestinationFile(repoId, direntModel.repo_name, direntModel.full_path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,9 @@ private void showNewDirDialog() {
ToastUtils.showLong(R.string.library_read_only);
return;
}
String rid = getNavContext().getRepoModel().repo_id;
String parentPath = getNavContext().getNavPath();
NewDirFileDialogFragment dialogFragment = NewDirFileDialogFragment.newInstance();
dialogFragment.initData(getNavContext().getRepoModel().repo_id, parentPath, true);
NewDirFileDialogFragment dialogFragment = NewDirFileDialogFragment.newInstance(rid, parentPath, true);
dialogFragment.setRefreshListener(new OnRefreshDataListener() {
@Override
public void onActionStatus(boolean isDone) {
Expand All @@ -1005,9 +1005,9 @@ private void showNewFileDialog() {
return;
}

String rid = getNavContext().getRepoModel().repo_id;
String parentPath = getNavContext().getNavPath();
NewDirFileDialogFragment dialogFragment = NewDirFileDialogFragment.newInstance();
dialogFragment.initData(getNavContext().getRepoModel().repo_id, parentPath, false);
NewDirFileDialogFragment dialogFragment = NewDirFileDialogFragment.newInstance(rid, parentPath, false);
dialogFragment.setRefreshListener(new OnRefreshDataListener() {
@Override
public void onActionStatus(boolean isDone) {
Expand Down
Loading

0 comments on commit 1261f95

Please sign in to comment.