-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from alexandr7035/develop
Release v0.1-alpha Implement basic use cases for Affinidi Cloud Wallet: - Sign up - Sign in - View info (username, DID) - Logout
- Loading branch information
Showing
83 changed files
with
2,801 additions
and
50 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package by.alexandr7035.affinidi_id.core | ||
|
||
import android.app.Application | ||
import by.alexandr7035.affinidi_id.BuildConfig | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import dagger.hilt.android.HiltAndroidApp | ||
import timber.log.Timber | ||
|
||
@HiltAndroidApp | ||
class App: Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
// Setup timber | ||
if (BuildConfig.DEBUG) { | ||
Timber.plant(Timber.DebugTree()) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/by/alexandr7035/affinidi_id/core/AppError.kt
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 by.alexandr7035.affinidi_id.core | ||
|
||
import java.io.IOException | ||
|
||
data class AppError(val errorType: ErrorType): IOException() |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/by/alexandr7035/affinidi_id/core/ErrorType.kt
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,11 @@ | ||
package by.alexandr7035.affinidi_id.core | ||
|
||
enum class ErrorType { | ||
FAILED_CONNECTION, | ||
USER_ALREADY_EXISTS, | ||
USER_DOES_NOT_EXIST, | ||
WRONG_USERNAME_OR_PASSWORD, | ||
WRONG_CONFIRMATION_CODE, | ||
CONFIRMATION_CODE_DIALOG_DISMISSED, | ||
UNKNOWN_ERROR | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/by/alexandr7035/affinidi_id/core/extensions/Context.kt
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,8 @@ | ||
package by.alexandr7035.affinidi_id.core.extensions | ||
|
||
import android.content.Context | ||
import android.widget.Toast | ||
|
||
fun Context.showToast(message: String, duration: Int = Toast.LENGTH_LONG) { | ||
Toast.makeText(this, message, duration).show() | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/by/alexandr7035/affinidi_id/core/extensions/Fragment.kt
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,11 @@ | ||
package by.alexandr7035.affinidi_id.core.extensions | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.navigation.fragment.findNavController | ||
import by.alexandr7035.affinidi_id.presentation.registration.RegistrationFragmentDirections | ||
|
||
fun Fragment.showErrorDialog(title: String, message: String) { | ||
findNavController().navigateSafe( | ||
RegistrationFragmentDirections | ||
.actionGlobalErrorDialogFragment(title, message)) | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/by/alexandr7035/affinidi_id/core/extensions/NavController.kt
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,14 @@ | ||
package by.alexandr7035.affinidi_id.core.extensions | ||
|
||
import androidx.navigation.NavController | ||
import androidx.navigation.NavDirections | ||
|
||
// Prevents crashes when second navigation request is triggered | ||
// from a fragment that is no longer the current destination | ||
fun NavController.navigateSafe(navDirection: NavDirections) { | ||
val action = currentDestination?.getAction(navDirection.actionId) | ||
|
||
if (action != null) { | ||
navigate(navDirection) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/main/java/by/alexandr7035/affinidi_id/core/extensions/String.kt
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,51 @@ | ||
package by.alexandr7035.affinidi_id.core.extensions | ||
|
||
import android.graphics.Typeface | ||
import android.text.SpannableString | ||
import android.text.Spanned | ||
import android.text.TextPaint | ||
import android.text.style.ClickableSpan | ||
import android.text.style.StyleSpan | ||
import android.view.View | ||
|
||
fun String.getClickableSpannable( | ||
clickableText: String, | ||
clickListener: View.OnClickListener, | ||
isBold: Boolean, | ||
spannableColor: Int? = null, | ||
isUnderlined: Boolean = true | ||
): SpannableString { | ||
|
||
val startIndex = this.indexOf(clickableText, startIndex = 0, ignoreCase = false) | ||
val endIndex = startIndex + clickableText.length | ||
|
||
val spannableString = SpannableString(this) | ||
|
||
val clickable = object : ClickableSpan() { | ||
override fun onClick(view: View) { | ||
clickListener.onClick(view) | ||
} | ||
|
||
override fun updateDrawState(ds: TextPaint) { | ||
super.updateDrawState(ds) | ||
ds.isUnderlineText = isUnderlined | ||
|
||
if (spannableColor != null) { | ||
ds.color = spannableColor | ||
} | ||
} | ||
} | ||
|
||
spannableString.setSpan(clickable, startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) | ||
|
||
if (isBold) { | ||
spannableString.setSpan( | ||
StyleSpan(Typeface.BOLD), | ||
startIndex, | ||
endIndex, | ||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | ||
) | ||
} | ||
|
||
return spannableString | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/by/alexandr7035/affinidi_id/core/extensions/TextInputLayout.kt
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,12 @@ | ||
package by.alexandr7035.affinidi_id.core.extensions | ||
|
||
import android.text.TextUtils | ||
import com.google.android.material.textfield.TextInputLayout | ||
|
||
fun TextInputLayout.clearError() { | ||
|
||
if (!TextUtils.isEmpty(error)) { | ||
error = null | ||
isErrorEnabled = false | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/by/alexandr7035/affinidi_id/core/extensions/Timber.kt
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 by.alexandr7035.affinidi_id.core.extensions | ||
|
||
import timber.log.Timber | ||
|
||
fun Timber.Forest.debug(message: String) { | ||
tag("DEBUG_TAG").d(message) | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/by/alexandr7035/affinidi_id/core/livedata/SingleLiveEvent.kt
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,44 @@ | ||
package by.alexandr7035.affinidi_id.core.livedata | ||
|
||
import android.util.Log | ||
import androidx.annotation.MainThread | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.Observer | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
class SingleLiveEvent<T>() : MutableLiveData<T>() { | ||
private val pending = AtomicBoolean(false) | ||
|
||
@MainThread | ||
override fun observe(owner: LifecycleOwner, observer: Observer<in T>) { | ||
if (hasActiveObservers()) { | ||
Log.w(TAG, "Multiple observers registered but only one will be notified of changes.") | ||
} | ||
|
||
// Observe the internal MutableLiveData | ||
super.observe(owner, Observer<T> { t -> | ||
if (pending.compareAndSet(true, false)) { | ||
observer.onChanged(t) | ||
} | ||
}) | ||
} | ||
|
||
@MainThread | ||
override fun setValue(t: T?) { | ||
pending.set(true) | ||
super.setValue(t) | ||
} | ||
|
||
/** | ||
* Used for cases where T is Void, to make calls cleaner. | ||
*/ | ||
@MainThread | ||
fun call() { | ||
value = null | ||
} | ||
|
||
companion object { | ||
private const val TAG = "SingleLiveEvent" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/by/alexandr7035/affinidi_id/core/network/AuthInterceptor.kt
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,21 @@ | ||
package by.alexandr7035.affinidi_id.core.network | ||
|
||
import by.alexandr7035.affinidi_id.BuildConfig | ||
import okhttp3.Interceptor | ||
import okhttp3.Request | ||
import okhttp3.Response | ||
|
||
class AuthInterceptor(): Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
// return chain.proceed(chain.request().withHeader("Authorization", "token ${appPreferences.token}")) | ||
|
||
val request = chain.request() | ||
|
||
val newRequest: Request = chain.request().newBuilder() | ||
.header("Api-Key", BuildConfig.API_KEY) | ||
.method(request.method, request.body) | ||
.build() | ||
|
||
return chain.proceed(newRequest) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/by/alexandr7035/affinidi_id/core/network/ErrorInterceptor.kt
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,31 @@ | ||
package by.alexandr7035.affinidi_id.core.network | ||
|
||
import by.alexandr7035.affinidi_id.core.App | ||
import by.alexandr7035.affinidi_id.core.AppError | ||
import by.alexandr7035.affinidi_id.core.ErrorType | ||
import by.alexandr7035.affinidi_id.core.extensions.debug | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import timber.log.Timber | ||
import java.net.ConnectException | ||
import java.net.UnknownHostException | ||
|
||
class ErrorInterceptor: Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
|
||
val res = try { | ||
chain.proceed(chain.request()) | ||
} | ||
catch (e: UnknownHostException) { | ||
e.printStackTrace() | ||
throw AppError(ErrorType.FAILED_CONNECTION) | ||
} | ||
catch (e: ConnectException) { | ||
e.printStackTrace() | ||
throw AppError(ErrorType.FAILED_CONNECTION) | ||
} | ||
|
||
Timber.debug("INTERCEPTOR ${res.code}") | ||
return res | ||
} | ||
} |
Oops, something went wrong.