Skip to content

Commit

Permalink
Fix compilation error on sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorNarvaez committed May 30, 2023
1 parent 826d0dc commit da0c722
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 244 deletions.
3 changes: 1 addition & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ rootProject.name = "omh-storage"
include(":storage-api")
include(":storage-api-drive-gms")
include(":storage-api-drive-nongms")
// Sample app is currently broken. Removed temporally
//include(":storage-sample")
include(":storage-sample")
4 changes: 3 additions & 1 deletion storage-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ val ngmsImplementation by configurations
dependencies {
implementation(project(":storage-api"))

ngmsImplementation("com.omh.android:auth-non-gms:1.0-SNAPSHOT")
//ngmsImplementation("com.omh.android:auth-non-gms:1.0-SNAPSHOT")
// Omh Auth
api(Libs.omhAuthLibrary)
ngmsImplementation(project(":storage-api-drive-nongms"))

implementation(Libs.coreKtx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ import dagger.hilt.components.SingletonComponent
@Module
@InstallIn(SingletonComponent::class)
class SingletonModule {

@Provides
fun providesOmhAuthClient(@ApplicationContext context: Context): OmhAuthClient {
return OmhAuthProvider.provideAuthClient(
scopes = listOf(
"openid",
"email",
"profile",
"https://www.googleapis.com/auth/drive.file"
),
clientId = BuildConfig.CLIENT_ID,
context = context
)
return OmhAuthProvider.Builder()
.addNonGmsPath(OmhAuthProvider.NGMS_ADDRESS)
.build()
.provideAuthClient(
context = context,
scopes = listOf(
"openid",
"email",
"profile",
"https://www.googleapis.com/auth/drive.file"
),
clientId = BuildConfig.CLIENT_ID
)
}

@Provides
fun providesOmhStorageClient(@ApplicationContext context: Context): OmhStorageClient {
return OmhStorageProvider.provideStorageClient(context)
fun providesOmhStorageClient(omhAuthClient: OmhAuthClient): OmhStorageClient {
return OmhStorageProvider.provideStorageClient(omhAuthClient)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.omh.android.storage.sample.databinding.ActivityFilesFoldersBinding
import com.omh.android.storage.sample.drive.adapter.grid.FilesFoldersGridAdapter
import com.omh.android.storage.sample.drive.adapter.grid.FileGridAdapter

class ActivityFilesAndFolders : AppCompatActivity() {

private lateinit var tvSortByName: TextView
private lateinit var rvFilesAndFolders: RecyclerView
private lateinit var rvGridAdapter: FilesFoldersGridAdapter
private lateinit var rvGridAdapter: FileGridAdapter

private val binding: ActivityFilesFoldersBinding by lazy {
ActivityFilesFoldersBinding.inflate(layoutInflater)
Expand All @@ -39,7 +39,7 @@ class ActivityFilesAndFolders : AppCompatActivity() {
tvSortByName.setOnClickListener {
// viewModel.sortByName()
}
rvGridAdapter = FilesFoldersGridAdapter()
rvGridAdapter = FileGridAdapter()
rvFilesAndFolders.setHasFixedSize(true)
rvFilesAndFolders.layoutManager = GridLayoutManager(this, 2)
rvFilesAndFolders.adapter = rvGridAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.omh.android.storage.api.domain.usecase.SortFilesAndFoldersByName
import com.omh.android.storage.sample.model.UiFileFolderItemData
import com.omh.android.storage.sample.mapper.fromFilesFoldersListToUi
import com.omh.android.storage.sample.usecase.KtsGetAllFilesAndFolders
import com.omh.android.storage.api.domain.model.OmhFile
import com.omh.android.storage.api.domain.usecase.GetFilesListWithParentIdUseCase
import com.omh.android.storage.api.domain.usecase.GetFilesListWithParentIdUseCaseParams
import com.omh.android.storage.api.domain.usecase.OmhResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class FilesAndFoldersViewModel(
private val getAllFilesAndFolders: KtsGetAllFilesAndFolders,
private val sortFilesAndFoldersByName: SortFilesAndFoldersByName
private val getFilesListWithParentIdUseCase: GetFilesListWithParentIdUseCase
) : ViewModel() {

private val _filesFoldersLiveData = MutableLiveData<List<UiFileFolderItemData>>()
val filesFoldersLiveData: LiveData<List<UiFileFolderItemData>> = _filesFoldersLiveData
private val _filesFoldersLiveData = MutableLiveData<List<OmhFile>>()
val filesFoldersLiveData: LiveData<List<OmhFile>> = _filesFoldersLiveData
private val _sortByNameAscendingLiveData = MutableLiveData<Boolean>()
val sortByNameAscendingLiveData: LiveData<Boolean> = _sortByNameAscendingLiveData

fun loadFilesFoldersFromRoot() {
viewModelScope.launch(Dispatchers.IO) {
_filesFoldersLiveData.postValue(
fromFilesFoldersListToUi(getAllFilesAndFolders.execute())
)

when (val result = getFilesListWithParentIdUseCase(GetFilesListWithParentIdUseCaseParams())) {
is OmhResult.OmhSuccess -> {
_filesFoldersLiveData.postValue(result.data.files)
}
is OmhResult.OmhError -> {}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ package com.omh.android.storage.sample.drive

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.omh.android.storage.api.domain.usecase.SortFilesAndFoldersByName
import com.omh.android.storage.sample.usecase.KtsGetAllFilesAndFolders
import com.omh.android.storage.api.domain.usecase.GetFilesListWithParentIdUseCase

class FilesAndFoldersViewModelFactory(
private val getAllFilesAndFolders: KtsGetAllFilesAndFolders,
private val sortFilesAndFoldersByName: SortFilesAndFoldersByName
private val getFilesListWithParentIdUseCase: GetFilesListWithParentIdUseCase,
) : ViewModelProvider.Factory {

@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return if (modelClass.isAssignableFrom(FilesAndFoldersViewModel::class.java)) {
FilesAndFoldersViewModel(
this.getAllFilesAndFolders,
this.sortFilesAndFoldersByName
this.getFilesListWithParentIdUseCase
) as T
} else {
throw IllegalArgumentException("ViewModel Not Found")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.omh.android.storage.sample.drive.adapter.grid

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.omh.android.storage.api.domain.model.OmhFile
import com.omh.android.storage.sample.databinding.RvItemFilefolderGridBinding

class FileGridAdapter : RecyclerView.Adapter<FileGridViewHolder>() {

private val files = mutableListOf<OmhFile>()

override fun getItemCount() = files.size

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int,
): FileGridViewHolder = FileGridViewHolder(
RvItemFilefolderGridBinding.inflate(
LayoutInflater.from(parent.context), parent, false
)
)

override fun onBindViewHolder(holder: FileGridViewHolder, position: Int) {
holder.bind(files[position])
}

fun addAll(items: List<OmhFile>) {
files.clear()
files.addAll(items)
notifyDataSetChanged()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.omh.android.storage.sample.drive.adapter.grid

import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.omh.android.storage.api.domain.model.OmhFile
import com.omh.android.storage.api.domain.model.OmhFileType
import com.omh.android.storage.sample.R
import com.omh.android.storage.sample.databinding.RvItemFilefolderGridBinding

class FileGridViewHolder(
binding: RvItemFilefolderGridBinding
) : RecyclerView.ViewHolder(binding.root) {

private val fileIcon: ImageView = binding.ivFileGridItem
private val fileName: TextView = binding.tvFileFolderGridItemName

private fun loadFileImage(url: String) {
Glide.with(itemView)
.asBitmap()
.load(url)
.centerCrop()
.placeholder(R.mipmap.ic_launcher)
.into(fileIcon)
}

fun bind(file: OmhFile) {
fileName.text = file.name

val iconLink = when (file.fileType) {
OmhFileType.PDF -> "https://drive-thirdparty.googleusercontent.com/32/type/application/pdf"

OmhFileType.DOCUMENT,
OmhFileType.MICROSOFT_WORD,
OmhFileType.OPEN_DOCUMENT_TEXT -> "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.document"

OmhFileType.SPREADSHEET,
OmhFileType.MICROSOFT_EXCEL,
OmhFileType.OPEN_DOCUMENT_SPREADSHEET -> "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.spreadsheet"

OmhFileType.PNG -> "https://drive-thirdparty.googleusercontent.com/32/type/image/png"

OmhFileType.ZIP -> "https://drive-thirdparty.googleusercontent.com/32/type/application/zip"

else -> "https://static.thenounproject.com/png/3482632-200.png"
}

loadFileImage(iconLink)
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit da0c722

Please sign in to comment.