-
-
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.
Merge pull request #126 from itszechs/multi-drive-client
Multiple drive clients support
- Loading branch information
Showing
56 changed files
with
2,106 additions
and
686 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
35 changes: 0 additions & 35 deletions
35
app/src/main/java/zechs/drive/stream/data/model/Account.kt
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
app/src/main/java/zechs/drive/stream/data/model/AccountWithClient.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,63 @@ | ||
package zechs.drive.stream.data.model | ||
|
||
import androidx.annotation.Keep | ||
import androidx.room.Entity | ||
import androidx.room.ForeignKey | ||
import androidx.room.Ignore | ||
import androidx.room.Index | ||
import androidx.room.PrimaryKey | ||
import com.google.gson.Gson | ||
import com.google.gson.reflect.TypeToken | ||
|
||
@Entity(tableName = "clients") | ||
data class Client( | ||
@PrimaryKey val id: String, | ||
val secret: String, | ||
val redirectUri: String | ||
) { | ||
fun isEmpty() = id.isEmpty() || secret.isEmpty() || redirectUri.isEmpty() | ||
} | ||
|
||
@Entity( | ||
tableName = "accounts", | ||
foreignKeys = [ForeignKey( | ||
entity = Client::class, | ||
parentColumns = ["id"], | ||
childColumns = ["clientId"], | ||
onDelete = ForeignKey.CASCADE | ||
)], | ||
indices = [Index("clientId")] | ||
) | ||
data class Account( | ||
@PrimaryKey val name: String, | ||
val refreshToken: String, | ||
val accessToken: String, | ||
val clientId: String | ||
) | ||
|
||
@Keep | ||
data class AccountWithClient( | ||
val name: String, | ||
val clientId: String, | ||
val clientSecret: String, | ||
val redirectUri: String, | ||
val refreshToken: String, | ||
val accessToken: String | ||
) { | ||
|
||
@Ignore | ||
var isDefault: Boolean = false | ||
|
||
fun getDriveClient() = DriveClient( | ||
clientId = clientId, | ||
clientSecret = clientSecret, | ||
redirectUri = redirectUri, | ||
scopes = listOf("https://www.googleapis.com/auth/drive") | ||
) | ||
|
||
fun getAccessTokenResponse(): TokenResponse { | ||
val type = object : TypeToken<TokenResponse>() {}.type | ||
return Gson().fromJson(accessToken, type) | ||
} | ||
|
||
} |
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
8 changes: 8 additions & 0 deletions
8
app/src/main/java/zechs/drive/stream/data/model/TokenRequestBody.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 zechs.drive.stream.data.model | ||
|
||
import com.google.errorprone.annotations.Keep | ||
|
||
@Keep | ||
data class TokenRequestBody( | ||
val token: String | ||
) |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/zechs/drive/stream/data/remote/RevokeTokenApi.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,15 @@ | ||
package zechs.drive.stream.data.remote | ||
|
||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
import zechs.drive.stream.data.model.TokenRequestBody | ||
|
||
interface RevokeTokenApi { | ||
|
||
@POST("/revoke") | ||
suspend fun revokeToken( | ||
@Body body: TokenRequestBody | ||
): Response<Unit> | ||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
app/src/main/java/zechs/drive/stream/ui/add_account/DialogAddAccount.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,39 @@ | ||
package zechs.drive.stream.ui.add_account | ||
|
||
import android.app.Dialog | ||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.Window | ||
import android.widget.Toast | ||
import com.google.android.material.button.MaterialButton | ||
import com.google.android.material.textfield.TextInputLayout | ||
import zechs.drive.stream.R | ||
|
||
class DialogAddAccount( | ||
context: Context, | ||
val onNextClickListener: (String) -> Unit | ||
) : Dialog(context, R.style.ThemeOverlay_Fade_MaterialAlertDialog) { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
requestWindowFeature(Window.FEATURE_NO_TITLE) | ||
setContentView(R.layout.dialog_new_account) | ||
|
||
val etNickname = findViewById<TextInputLayout>(R.id.tf_nickname).editText!! | ||
val nextButton = findViewById<MaterialButton>(R.id.btn_next) | ||
|
||
nextButton.setOnClickListener { | ||
if (etNickname.text.toString().isEmpty()) { | ||
Toast.makeText( | ||
context, | ||
context.getString(R.string.please_enter_a_nickname), | ||
Toast.LENGTH_SHORT | ||
).show() | ||
} else { | ||
onNextClickListener.invoke(etNickname.text.toString()) | ||
dismiss() | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.