-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring (split code into packages / add custom exception handling)
- Loading branch information
1 parent
8676b56
commit 70831be
Showing
17 changed files
with
324 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...countimporter/helper/IThreadListener.java → ...accountimporter/aidl/IThreadListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ountimporter/helper/NextcloudRequest.java → ...ccountimporter/aidl/NextcloudRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...n/java/de/luhmer/owncloud/accountimporter/exceptions/CurrentAccountNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.luhmer.owncloud.accountimporter.exceptions; | ||
|
||
import android.content.Context; | ||
|
||
public class CurrentAccountNotFoundException extends SSOException { | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...luhmer/owncloud/accountimporter/exceptions/NextcloudFilesAppAccountNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package de.luhmer.owncloud.accountimporter.exceptions; | ||
|
||
public class NextcloudFilesAppAccountNotFoundException extends SSOException { | ||
} |
4 changes: 4 additions & 0 deletions
4
...de/luhmer/owncloud/accountimporter/exceptions/NextcloudFilesAppNotInstalledException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package de.luhmer.owncloud.accountimporter.exceptions; | ||
|
||
public class NextcloudFilesAppNotInstalledException extends SSOException { | ||
} |
7 changes: 7 additions & 0 deletions
7
...java/de/luhmer/owncloud/accountimporter/exceptions/NoCurrentAccountSelectedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.luhmer.owncloud.accountimporter.exceptions; | ||
|
||
import android.content.Context; | ||
|
||
public class NoCurrentAccountSelectedException extends SSOException { | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/de/luhmer/owncloud/accountimporter/exceptions/SSOException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package de.luhmer.owncloud.accountimporter.exceptions; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import de.luhmer.owncloud.accountimporter.R; | ||
import de.luhmer.owncloud.accountimporter.model.ExceptionMessage; | ||
|
||
public class SSOException extends Exception { | ||
|
||
private ExceptionMessage em; | ||
|
||
public SSOException() { | ||
super("Single Sign On Exception (use getMessage(context) for more information)"); | ||
} | ||
|
||
private void loadExceptionMessage(Context context) { | ||
em = new ExceptionMessage(); | ||
|
||
Log.d("AAAAAA", "this.getClass(): " + this.getClass()); | ||
|
||
if(this instanceof CurrentAccountNotFoundException) { | ||
em.title = context.getString(R.string.current_account_not_found_exception_title); | ||
em.message = context.getString(R.string.current_account_not_found_exception_message); | ||
} else if(this instanceof NoCurrentAccountSelectedException) { | ||
em.title = context.getString(R.string.no_current_account_selected_exception_title); | ||
em.message = context.getString(R.string.no_current_account_selected_exception_message); | ||
} else if(this instanceof TokenMismatchException) { | ||
em.title = context.getString(R.string.token_mismatch_title); | ||
em.message = context.getString(R.string.token_mismatch_message); | ||
} else if(this instanceof NextcloudFilesAppNotInstalledException) { | ||
em.title = context.getString(R.string.nextcloud_files_app_not_installed_title); | ||
em.message = context.getString(R.string.nextcloud_files_app_not_installed_message); | ||
} else if(this instanceof NextcloudFilesAppAccountNotFoundException) { | ||
em.title = context.getString(R.string.nextcloud_files_app_account_not_found_title); | ||
em.message = context.getString(R.string.nextcloud_files_app_account_not_found_message); | ||
} else { | ||
em.title = "Unknown error"; | ||
em.message = "Unknown error.."; | ||
} | ||
} | ||
|
||
public String getTitle(Context context) { | ||
if(em == null) { | ||
loadExceptionMessage(context); | ||
} | ||
return em.title; | ||
} | ||
|
||
public String getMessage(Context context) { | ||
if(em == null) { | ||
loadExceptionMessage(context); | ||
} | ||
return em.message; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
// If already loaded.. return it | ||
if(em != null) { | ||
return em.message; | ||
} | ||
|
||
// Otherwise try to get the application via reflection | ||
Application app = getApplication(); | ||
if(app != null) { | ||
loadExceptionMessage(app); | ||
return em.message; | ||
} | ||
|
||
// If that didn't work.. well return the "generic" base message | ||
return super.getMessage(); | ||
} | ||
|
||
private Application getApplication() { | ||
try { | ||
return (Application) Class.forName("android.app.ActivityThread") | ||
.getMethod("currentApplication").invoke(null, (Object[]) null); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/de/luhmer/owncloud/accountimporter/exceptions/TokenMismatchException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.luhmer.owncloud.accountimporter.exceptions; | ||
|
||
public class TokenMismatchException extends SSOException { | ||
|
||
} |
Oops, something went wrong.