generated from teamqomunal/android-research-tech
-
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.
- Loading branch information
1 parent
e237371
commit 09be3e8
Showing
16 changed files
with
494 additions
and
57 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
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/qomunal/opensource/androidresearch/common/base/BaseFragment.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,56 @@ | ||
package com.qomunal.opensource.androidresearch.common.base | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.viewbinding.ViewBinding | ||
|
||
/** | ||
* Created by faisalamircs on 21/01/2024 | ||
* ----------------------------------------- | ||
* Name : Muhammad Faisal Amir | ||
* E-mail : [email protected] | ||
* Github : github.com/amirisback | ||
* ----------------------------------------- | ||
*/ | ||
|
||
|
||
abstract class BaseFragment<VB : ViewBinding> : Fragment() { | ||
|
||
companion object { | ||
val TAG: String = BaseFragment::class.java.simpleName | ||
} | ||
|
||
private var _binding: VB? = null | ||
|
||
protected val binding: VB get() = _binding!! | ||
|
||
abstract fun setupViewBinding(inflater: LayoutInflater, container: ViewGroup?): VB | ||
|
||
abstract fun initUI(savedInstanceState: Bundle?) | ||
|
||
abstract fun initObserver() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
_binding = setupViewBinding(inflater, container) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
initUI(savedInstanceState) | ||
initObserver() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
_binding = null | ||
} | ||
|
||
} |
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
53 changes: 53 additions & 0 deletions
53
app/src/main/java/com/qomunal/opensource/androidresearch/common/ext/ImageViewExt.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,53 @@ | ||
package com.qomunal.opensource.androidresearch.common.ext | ||
|
||
import android.net.Uri | ||
import android.widget.ImageView | ||
import com.bumptech.glide.Glide | ||
import com.bumptech.glide.load.engine.DiskCacheStrategy | ||
import com.qomunal.opensource.androidresearch.R | ||
|
||
/** | ||
* Created by faisalamircs on 21/01/2024 | ||
* ----------------------------------------- | ||
* Name : Muhammad Faisal Amir | ||
* E-mail : [email protected] | ||
* Github : github.com/amirisback | ||
* ----------------------------------------- | ||
*/ | ||
|
||
|
||
fun ImageView.setImageExt( | ||
uri: Any? = null, | ||
placeHolder: Int = R.drawable.ic_launcher_background, | ||
isCenterCrop: Boolean = false | ||
) { | ||
if (uri != null) { | ||
when (uri) { | ||
is String, | ||
is Int, | ||
is Uri, | ||
is ByteArray -> { | ||
if (isCenterCrop) { | ||
Glide.with(context) | ||
.load(uri) | ||
.placeholder(placeHolder) | ||
.diskCacheStrategy(DiskCacheStrategy.ALL) | ||
.centerCrop() | ||
.into(this) | ||
} else { | ||
Glide.with(context) | ||
.load(uri) | ||
.placeholder(placeHolder) | ||
.diskCacheStrategy(DiskCacheStrategy.ALL) | ||
.into(this) | ||
} | ||
|
||
} | ||
} | ||
} else { | ||
Glide.with(context) | ||
.load("") | ||
.placeholder(placeHolder) | ||
.into(this) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/qomunal/opensource/androidresearch/model/MainModel.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,25 @@ | ||
package com.qomunal.opensource.androidresearch.model | ||
|
||
import android.os.Parcelable | ||
import androidx.annotation.Keep | ||
import kotlinx.parcelize.Parcelize | ||
|
||
/** | ||
* Created by faisalamircs on 21/01/2024 | ||
* ----------------------------------------- | ||
* Name : Muhammad Faisal Amir | ||
* E-mail : [email protected] | ||
* Github : github.com/amirisback | ||
* ----------------------------------------- | ||
*/ | ||
|
||
|
||
@Keep | ||
@Parcelize | ||
data class MainModel( | ||
var title: String, | ||
var description: String, | ||
var image: String, | ||
var data: String, | ||
) : Parcelable | ||
|
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
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/qomunal/opensource/androidresearch/ui/main/MainAdapter.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,41 @@ | ||
package com.qomunal.opensource.androidresearch.ui.main | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.qomunal.opensource.androidresearch.databinding.ItemMainBinding | ||
import com.qomunal.opensource.androidresearch.model.MainModel | ||
|
||
/** | ||
* Created by faisalamircs on 21/01/2024 | ||
* ----------------------------------------- | ||
* Name : Muhammad Faisal Amir | ||
* E-mail : [email protected] | ||
* Github : github.com/amirisback | ||
* ----------------------------------------- | ||
*/ | ||
|
||
|
||
class MainAdapter : RecyclerView.Adapter<MainHolder>() { | ||
|
||
var listItems = mutableListOf<MainModel>() | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainHolder { | ||
val binding = ItemMainBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return MainHolder(binding) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return listItems.size | ||
} | ||
|
||
override fun onBindViewHolder(holder: MainHolder, position: Int) { | ||
holder.bind(listItems[position]) | ||
} | ||
|
||
fun setItem(item: MutableList<MainModel>) { | ||
listItems = item | ||
notifyDataSetChanged() | ||
} | ||
|
||
} |
Oops, something went wrong.