Explorar el Código

+ main sbc in progress

Dola TENG hace 2 años
padre
commit
d47f5fc07c

+ 6 - 0
.idea/misc.xml

@@ -3,6 +3,12 @@
   <component name="DesignSurface">
     <option name="filePathToZoomLevelMap">
       <map>
+        <entry key="..\:/3-Work/Android/SBC_Main_Android/app/src/main/res/drawable/app_background.xml" value="0.3675" />
+        <entry key="..\:/3-Work/Android/SBC_Main_Android/app/src/main/res/layout/activity_main.xml" value="0.36666666666666664" />
+        <entry key="..\:/3-Work/Android/SBC_Main_Android/app/src/main/res/layout/app_bar.xml" value="0.36666666666666664" />
+        <entry key="..\:/3-Work/Android/SBC_Main_Android/app/src/main/res/layout/fragment_report.xml" value="0.18802083333333333" />
+        <entry key="..\:/3-Work/Android/SBC_Main_Android/app/src/main/res/layout/layout_fragment_main_yuki.xml" value="0.36666666666666664" />
+        <entry key="..\:/3-Work/Android/SBC_Main_Android/app/src/main/res/layout/layout_main_module.xml" value="0.36666666666666664" />
         <entry key="..\:/3-Work/Android/Yuki-Mobile/app/src/main/res/layout/bet_detail_item.xml" value="0.33" />
         <entry key="..\:/3-Work/Android/Yuki-Mobile/app/src/main/res/layout/betting_detail.xml" value="0.36666666666666664" />
         <entry key="..\:/3-Work/Android/Yuki-Mobile/app/src/main/res/layout/fragment_play.xml" value="0.2807971014492754" />

+ 0 - 8
app/build.gradle

@@ -37,7 +37,6 @@ android {
         }
         release {
             manifestPlaceholders = [enableCrashlytic: false]
-//            firebaseCrashlytics.mappingFileUploadEnabled true
             shrinkResources false
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
@@ -146,13 +145,6 @@ dependencies {
     implementation project(path: ':printooth')
     implementation 'com.squareup.picasso:picasso:2.71828'
 
-    //Firebase
-    // Import the BoM for the Firebase platform
-//    implementation platform('com.google.firebase:firebase-bom:26.4.0')
-//    implementation 'com.google.firebase:firebase-crashlytics-ktx'
-//    implementation 'com.google.firebase:firebase-analytics-ktx'
-//    implementation 'com.google.firebase:firebase-config-ktx'
-
     implementation 'nl.dionsegijn:konfetti:1.3.2'
 
     testImplementation 'junit:junit:4.13.2'

+ 2 - 1
app/src/main/java/com/khmer9/yuki/adapter/MainModuleAdapter.kt

@@ -5,11 +5,12 @@ import android.view.ViewGroup
 import androidx.recyclerview.widget.RecyclerView
 import com.gdtlib.lib.adapter.BaseListAdapter
 import com.khmer9.yuki.R
+import com.khmer9.yuki.screen.main.MainModuleViewHolder
 import com.khmer9.yuki.screen.report.bettingStatement.ReportBettingViewHolder
 
 class MainModuleAdapter : BaseListAdapter() {
     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
-        return ReportBettingViewHolder(
+        return MainModuleViewHolder(
             LayoutInflater.from(parent.context).inflate(
                 R.layout.layout_main_module,
                 parent,

+ 6 - 3
app/src/main/java/com/khmer9/yuki/remote/MainModuleDataModel.kt

@@ -1,5 +1,6 @@
 package com.khmer9.yuki.remote
 
+import com.gdtlib.lib.adapter.BaseListItem
 import com.squareup.moshi.Json
 import com.squareup.moshi.JsonClass
 
@@ -12,7 +13,7 @@ data class MainModuleResponse(
     val message: MainModuleMessage,
 
     @Json(name = "data")
-    val data: List<MainModuleData>?
+    val data: List<ModuleData>?
 )
 
 @JsonClass(generateAdapter = true)
@@ -25,7 +26,7 @@ data class MainModuleMessage(
 )
 
 @JsonClass(generateAdapter = true)
-data class MainModuleData(
+data class ModuleData(
     @Json(name = "_id")
     val id: String,
 
@@ -55,4 +56,6 @@ data class MainModuleData(
 
     @Json(name = "order")
     val order: Int,
-)
+) : BaseListItem() {
+    override fun getUnique(): String = id
+}

+ 70 - 2
app/src/main/java/com/khmer9/yuki/screen/main/MainFragment.kt

@@ -2,25 +2,42 @@ package com.khmer9.yuki.screen.main
 
 import android.annotation.SuppressLint
 import android.content.Intent
+import android.media.MediaPlayer
 import android.os.Bundle
 import android.util.Log
 import android.view.View
 import android.widget.Toast
+import androidx.core.view.isVisible
+import androidx.lifecycle.Observer
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
 import com.khmer9.yuki.R
+import com.khmer9.yuki.adapter.MainModuleAdapter
 import com.khmer9.yuki.app.App
 import com.khmer9.yuki.app.ShareActivity
 import com.khmer9.yuki.base.BaseFragment
+import com.khmer9.yuki.extension.btnClick
+import com.khmer9.yuki.remote.User
 import com.khmer9.yuki.remote.service.ConnectivityStates
+import com.khmer9.yuki.screen.report.StatementFragment
 import com.khmer9.yuki.screen.splash.SplashScreenActivity
+import kotlinx.android.synthetic.main.fragment_report.*
 
 class MainFragment : BaseFragment(R.layout.layout_fragment_main_yuki) {
     private val shareViewModel = App.injectShareViewModel()
     private val sharePref = App.injectPrefHelper()
+    private lateinit var user: User
+
+    private lateinit var adapter: MainModuleAdapter
+    private lateinit var recyclerView: RecyclerView
+
+    private lateinit var betTouch: MediaPlayer
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         (requireActivity() as ShareActivity).apply {
-            //user = loginData.user!!
+            user = loginData.user!!
+            betTouch = MediaPlayer.create(this, R.raw.bettouch)
         }
     }
 
@@ -28,9 +45,60 @@ class MainFragment : BaseFragment(R.layout.layout_fragment_main_yuki) {
         super.onViewCreated(view, savedInstanceState)
 
         (requireActivity() as ShareActivity).apply {
-            //userNameTextView.text = user.userName
+            userNameTextView.text = user.userName
+
+            val balance = currencyFormat(user.accountBalances)
+            when (user.currencyType) {
+                1 -> {//dollar
+                    balanceTextView.text = "$balance $"
+                }
+                2 -> {//riel
+                    balanceTextView.text = "$balance ៛"
+                }
+                3 -> {//baht
+                    balanceTextView.text = "$balance ฿"
+                }
+            }
+
+            reportImageView.setOnClickListener {
+                if (!sharePref.getIsMute()) betTouch.start()
+                it.btnClick().subscribe {
+                    supportFragmentManager.beginTransaction()
+                        .setCustomAnimations(
+                            R.anim.slide_in,
+                            R.anim.slide_out,
+                            R.anim.slide_in_exit,
+                            R.anim.slide_out_exit
+                        )
+                        .add(R.id.container, StatementFragment().apply {
+                            arguments =
+                                Bundle().apply {
+                                }
+                        })
+                        .addToBackStack(null)
+                        .commit()
+                }
+            }
         }
 
+        //
+        recyclerView = view.findViewById(R.id.rv_main)
+
+        //
+        shareViewModel.remoteMainModule()
+        shareViewModel.getMainModuleState.observe(viewLifecycleOwner, Observer {
+            setModuleMain(it)
+        })
+    }
+
+    private fun setModuleMain(state: ResultMainState) {
+        if (state.resultList != null) {
+            adapter = MainModuleAdapter()
+            adapter.submitList(state.resultList)
+            recyclerView.setHasFixedSize(true)
+            recyclerView.layoutManager = LinearLayoutManager(context)
+            recyclerView.adapter = adapter
+        }
     }
 
     @SuppressLint("CheckResult")

+ 50 - 0
app/src/main/java/com/khmer9/yuki/screen/main/MainModuleViewHolder.kt

@@ -0,0 +1,50 @@
+package com.khmer9.yuki.screen.main
+
+import android.annotation.SuppressLint
+import android.graphics.Bitmap
+import android.graphics.BitmapFactory
+import android.net.Uri
+import android.os.AsyncTask
+import android.util.Log
+import android.view.View
+import android.widget.ImageView
+import android.widget.TextView
+import android.widget.Toast
+import com.gdtlib.lib.adapter.BaseListItem
+import com.gdtlib.lib.viewholder.BaseListViewHolder
+import com.khmer9.yuki.R
+import com.khmer9.yuki.remote.ModuleData
+import com.khmer9.yuki.util.ModelPreferencesManager.with
+import com.squareup.picasso.Picasso
+import java.lang.System.load
+
+class MainModuleViewHolder(itemView: View) : BaseListViewHolder(itemView) {
+    private val picasso = Picasso.get()
+
+    override fun bindView(item: BaseListItem) {
+        val imgIcon = itemView.findViewById<ImageView>(R.id.img_icon)
+        val tvName = itemView.findViewById<TextView>(R.id.tv_name)
+
+        if (item is ModuleData) {
+            tvName.text = item.name
+
+            try {
+                val displayMetrics = itemView.context.resources.displayMetrics
+                val pxWidth = displayMetrics.widthPixels
+                val pxHeight = displayMetrics.heightPixels
+                val dpWidth = pxWidth / displayMetrics.density
+                val dpHeight = pxHeight / displayMetrics.density
+
+                val height = dpHeight * 0.4804f
+                imgIcon.layoutParams.height = height.toInt()
+                imgIcon.layoutParams.width = height.toInt()
+
+                picasso
+                    .load(item.smallIcon)
+                    .placeholder(R.drawable.animal_seven)
+                    .into(imgIcon)
+            } catch (e: Exception) {
+            }
+        }
+    }
+}

+ 2 - 2
app/src/main/java/com/khmer9/yuki/screen/main/ResultMainState.kt

@@ -1,10 +1,10 @@
 package com.khmer9.yuki.screen.main
 
-import com.khmer9.yuki.remote.MainModuleData
+import com.khmer9.yuki.remote.ModuleData
 
 data class ResultMainState(
     val initial: Boolean = true,
     val isProgress: Boolean = false,
     val error: String? = null,
-    var resultList: List<MainModuleData>? = null,
+    var resultList: List<ModuleData>? = null,
 )

+ 7 - 12
app/src/main/res/layout/layout_main_module.xml

@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical">
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:padding="5dp">
 
     <androidx.appcompat.widget.LinearLayoutCompat
         android:layout_width="match_parent"
@@ -12,16 +13,10 @@
 
         <ImageView
             android:id="@+id/img_icon"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center"
-            android:padding="5dp"
-            android:src="@drawable/animal_eight" />
-
-        <View
             android:layout_width="match_parent"
-            android:layout_height="1dp"
-            android:background="@color/color_blue_800" />
+            android:layout_height="100dp"
+            android:layout_gravity="center"
+            android:padding="5dp" />
 
         <TextView
             android:id="@+id/tv_name"
@@ -31,7 +26,7 @@
             android:padding="5dp"
             android:text="Goat"
             android:textColor="@color/text_black"
-            android:textSize="14sp"
+            android:textSize="20sp"
             android:textStyle="bold" />
 
     </androidx.appcompat.widget.LinearLayoutCompat>