-
Notifications
You must be signed in to change notification settings - Fork 1
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
Steve Pha
authored and
Steve Pha
committed
Jan 20, 2023
0 parents
commit e2aabd4
Showing
65 changed files
with
2,635 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# NativeAds-RecyclerView |
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 @@ | ||
/build |
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,54 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.saitawngpha.nativerecyclerview' | ||
compileSdk 32 | ||
|
||
defaultConfig { | ||
applicationId "com.saitawngpha.nativerecyclerview" | ||
minSdk 21 | ||
targetSdk 32 | ||
versionCode 1 | ||
versionName "1.0.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
|
||
buildFeatures{ | ||
viewBinding true | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation 'androidx.appcompat:appcompat:1.5.0' | ||
implementation 'com.google.android.material:material:1.7.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
|
||
implementation project(path: ':nativetemplates') | ||
//cardview | ||
implementation 'androidx.cardview:cardview:1.0.0' | ||
//ads | ||
implementation 'com.google.android.gms:play-services-ads:21.4.0' | ||
} |
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 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/saitawngpha/nativerecyclerview/ExampleInstrumentedTest.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,24 @@ | ||
package com.saitawngpha.nativerecyclerview | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.saitawngpha.nativerecyclerview", appContext.packageName) | ||
} | ||
} |
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,36 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.NativeRecyclerview" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
|
||
<meta-data | ||
android:name="android.app.lib_name" | ||
android:value="" /> | ||
</activity> | ||
|
||
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 --> | ||
<meta-data | ||
android:name="com.google.android.gms.ads.APPLICATION_ID" | ||
android:value="ca-app-pub-3940256099942544~3347511713"/> | ||
|
||
</application> | ||
|
||
</manifest> |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/saitawngpha/nativerecyclerview/MainActivity.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,43 @@ | ||
package com.saitawngpha.nativerecyclerview | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.google.rvadapter.AdmobNativeAdAdapter | ||
import com.saitawngpha.nativerecyclerview.adapter.MyAdapter | ||
import com.saitawngpha.nativerecyclerview.databinding.ActivityMainBinding | ||
import com.saitawngpha.nativerecyclerview.model.UserModel | ||
|
||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private val myAdapter by lazy { MyAdapter() } | ||
private lateinit var binding: ActivityMainBinding | ||
private var dataList = arrayOf("Sai Maung Ngin", "Ying Noom Hom Kham", "Nang Noung Lao Hurng", "Sai Maurng Zurn", "Aii Khun Tai", "Mo Khur Khun", "Mork Zarm Kham", "Hpoi Hseng Hurng") | ||
private var data = mutableListOf<UserModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityMainBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
binding.apply { | ||
recyclerView.layoutManager = LinearLayoutManager(this@MainActivity) | ||
val admobNativeAdAdapter: AdmobNativeAdAdapter = AdmobNativeAdAdapter.Builder | ||
.with( | ||
"ca-app-pub-3940256099942544/2247696110", //Create a native ad id from admob console | ||
myAdapter, //The adapter you would normally set to your recyClerView | ||
"medium" //Set it with "small","medium" or "custom" | ||
) | ||
.adItemIterval(2) //native ad repeating interval in the recyclerview | ||
.build() | ||
recyclerView.adapter = admobNativeAdAdapter | ||
} | ||
|
||
for (i in 0 until dataList.size){ | ||
data.add(UserModel(dataList[i])) | ||
} | ||
|
||
myAdapter.differ.submitList(data) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
app/src/main/java/com/saitawngpha/nativerecyclerview/adapter/MyAdapter.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 com.saitawngpha.nativerecyclerview.adapter | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.AsyncListDiffer | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.saitawngpha.nativerecyclerview.databinding.UserItemsBinding | ||
import com.saitawngpha.nativerecyclerview.model.UserModel | ||
|
||
/** | ||
* @Author: ၸၢႆးတွင်ႉၾႃႉ | ||
* @Date: 1/19/23 | ||
*/ | ||
class MyAdapter: RecyclerView.Adapter<MyAdapter.ViewHolder>() { | ||
|
||
private lateinit var binding: UserItemsBinding | ||
private lateinit var context: Context | ||
|
||
inner class ViewHolder(): RecyclerView.ViewHolder(binding.root){ | ||
fun set(item: UserModel){ | ||
binding.apply { | ||
nameTxt.text = item.name | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
binding = UserItemsBinding.inflate(inflater, parent, false) | ||
context = parent.context | ||
return ViewHolder() | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.set(differ.currentList[position]) | ||
holder.setIsRecyclable(false) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return differ.currentList.size | ||
} | ||
|
||
private val differCallback = object : DiffUtil.ItemCallback<UserModel>(){ | ||
override fun areItemsTheSame( | ||
oldItem: UserModel, | ||
newItem: UserModel | ||
): Boolean { | ||
return oldItem.name == newItem.name | ||
} | ||
|
||
override fun areContentsTheSame( | ||
oldItem: UserModel, | ||
newItem: UserModel | ||
): Boolean { | ||
return oldItem == newItem | ||
} | ||
} | ||
|
||
val differ = AsyncListDiffer(this, differCallback) | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/saitawngpha/nativerecyclerview/model/UserModel.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 com.saitawngpha.nativerecyclerview.model | ||
|
||
/** | ||
* @Author: ၸၢႆးတွင်ႉၾႃႉ | ||
* @Date: 1/19/23 | ||
*/ | ||
|
||
data class UserModel(val name: String) |
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,30 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="108" | ||
android:viewportHeight="108"> | ||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:endX="85.84757" | ||
android:endY="92.4963" | ||
android:startX="42.9492" | ||
android:startY="49.59793" | ||
android:type="linear"> | ||
<item | ||
android:color="#44000000" | ||
android:offset="0.0" /> | ||
<item | ||
android:color="#00000000" | ||
android:offset="1.0" /> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:fillType="nonZero" | ||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" | ||
android:strokeWidth="1" | ||
android:strokeColor="#00000000" /> | ||
</vector> |
Oops, something went wrong.