Skip to content

Commit

Permalink
Restore webdav files
Browse files Browse the repository at this point in the history
  • Loading branch information
wizmer committed Sep 8, 2016
1 parent 4bb8ea7 commit 5e242eb
Show file tree
Hide file tree
Showing 7 changed files with 709 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.matburt.mobileorg.Gui;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.matburt.mobileorg.R;

public class CertificateConflictActivity extends Activity {

private TextView hash_details;
private TextView cert_descr;
private Button accept_button;
private Button deny_button;
private View.OnClickListener acceptListener = new View.OnClickListener() {
public void onClick(View v) {
accept();
finish();
}
};
private View.OnClickListener denyListener = new View.OnClickListener() {
public void onClick(View v) {
finish();
}
};

public void onCreate(Bundle savedInstanceState) {
// OrgUtils.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.certconflict);

this.hash_details = (TextView) this.findViewById(R.id.cert_hash_details);
this.cert_descr = (TextView) this.findViewById(R.id.cert_new_descr);
this.accept_button = (Button) this.findViewById(R.id.cert_conflict_accept);
this.accept_button.setOnClickListener(acceptListener);
this.deny_button = (Button) this.findViewById(R.id.cert_conflict_deny);
this.deny_button.setOnClickListener(denyListener);

SharedPreferences appSettings =
PreferenceManager.getDefaultSharedPreferences(this);
String webCertHash = Integer.toString(appSettings.getInt("webCertHash", 0));
String conflictHash = Integer.toString(appSettings.getInt("webConflictHash", 0));
String conflictDetails = appSettings.getString("webConflictHashDesc", "");
this.hash_details.setText("Previous Hash: " + webCertHash + " does not match the current one: " + conflictHash);
this.cert_descr.setText("The New Certificate Looks like this:\n" + conflictDetails);
}

private void accept() {
SharedPreferences appSettings =
PreferenceManager.getDefaultSharedPreferences(this);
Editor edit = appSettings.edit();
edit.putInt("webCertHash", appSettings.getInt("webConflictHash", 0));
edit.putString("webCertDesscr", appSettings.getString("webConflictHashDesc", ""));
edit.commit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.matburt.mobileorg.Gui.Wizard.Wizards;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.HandlerThread;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.matburt.mobileorg.Gui.Wizard.WizardView;
import com.matburt.mobileorg.R;
import com.matburt.mobileorg.Synchronizers.WebDAVSynchronizer;

public class WebDAVWizard extends Wizard {

private EditText webdavUser;
private EditText webdavPass;
private EditText webdavUrl;

public WebDAVWizard(WizardView wizardView, Context context) {
super(wizardView, context);
}


@Override
public void setupFirstPage() {
createWebDAVConfig();
}

public View createWebDAVConfig() {
wizardView.removePagesAfter(1);

View view = LayoutInflater.from(context).inflate(
R.layout.wizard_webdav, null);

webdavUser = (EditText) view
.findViewById(R.id.wizard_webdav_username);
webdavPass = (EditText) view
.findViewById(R.id.wizard_webdav_password);
webdavUrl = (EditText) view.findViewById(R.id.wizard_webdav_url);
Button webdavLoginButton = (Button) view
.findViewById(R.id.wizard_webdav_login_button);
webdavLoginButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
loginWebdav();
}
});

setupDoneButton(view);
wizardView.addPage(view);
wizardView.setNavButtonStateOnPage(1, true, WizardView.LAST_PAGE);
wizardView.enablePage(1);
return view;
}



public void loginWebdav() {
final String urlActual = webdavUrl.getText().toString();
final String passActual = webdavPass.getText().toString();
final String userActual = webdavUser.getText().toString();
progress.show();

Thread uiThread = new HandlerThread("UIHandler");
uiThread.start();
uiHandler = new UIHandler(((HandlerThread) uiThread).getLooper());

Thread loginThread = new Thread() {
public void run() {
WebDAVSynchronizer wds = new WebDAVSynchronizer(context);
String extra = wds.testConnection(urlActual, userActual,
passActual);
if (extra != null) {
showToastRemote("Login failed: " + extra);
return;
}
showToastRemote("Login succeeded");
}
};
loginThread.start();
}

public void saveSettings() {
SharedPreferences appSettings = PreferenceManager
.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = appSettings.edit();

editor.putString("syncSource", "webdav");

editor.putString("webUrl", webdavUrl.getText().toString());
editor.putString("webPass", webdavPass.getText().toString());
editor.putString("webUser", webdavUser.getText().toString());

editor.apply();
((Activity) context).finish();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.matburt.mobileorg.Settings.Synchronizers;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

import com.matburt.mobileorg.R;

public class WebDAVSettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener
{
public static final String KEY_WEB_URL = "webUrl";
public static final String KEY_WEB_USER = "webUser";
public static final String KEY_WEB_PASS = "webPass";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.webdav_preferences);
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
setPreferenceSummary(shared, KEY_WEB_URL);
setPreferenceSummary(shared, KEY_WEB_USER);
}
@Override
public void onPause() {
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}

@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// Set up the initial values following the Settings design guidelines for Ice Cream Sandwich
// Settings should show their current value instead of a description
setPreferenceSummary(sharedPreferences, key);
}

protected void setPreferenceSummary(SharedPreferences sharedPreferences, String key) {
Preference pref = findPreference(key);
if (pref != null) {
if (key.equals(KEY_WEB_URL) || key.equals(KEY_WEB_USER)) {
String value = sharedPreferences.getString(key, "");
pref.setSummary(value);
}
}
}
}
Loading

0 comments on commit 5e242eb

Please sign in to comment.