use ListView for library fragment
This commit is contained in:
		
							
								
								
									
										7
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -39,12 +39,7 @@ captures/ | |||||||
|  |  | ||||||
| # IntelliJ | # IntelliJ | ||||||
| *.iml | *.iml | ||||||
| .idea/workspace.xml | .idea/ | ||||||
| .idea/tasks.xml |  | ||||||
| .idea/gradle.xml |  | ||||||
| .idea/assetWizardSettings.xml |  | ||||||
| .idea/dictionaries |  | ||||||
| .idea/libraries |  | ||||||
| # Android Studio 3 in .gitignore file. | # Android Studio 3 in .gitignore file. | ||||||
| .idea/caches | .idea/caches | ||||||
| .idea/modules.xml | .idea/modules.xml | ||||||
|  | |||||||
| @ -4,16 +4,11 @@ import android.os.Bundle | |||||||
| import android.view.LayoutInflater | import android.view.LayoutInflater | ||||||
| import android.view.View | import android.view.View | ||||||
| import android.view.ViewGroup | import android.view.ViewGroup | ||||||
| import android.widget.ArrayAdapter |  | ||||||
| import androidx.fragment.app.Fragment | import androidx.fragment.app.Fragment | ||||||
| import kotlinx.android.synthetic.main.fragment_library.* | import kotlinx.android.synthetic.main.fragment_library.* | ||||||
| import kotlinx.coroutines.Dispatchers | import kotlinx.coroutines.* | ||||||
| import kotlinx.coroutines.GlobalScope |  | ||||||
| import kotlinx.coroutines.launch |  | ||||||
| import kotlinx.coroutines.withContext |  | ||||||
| import org.mosad.teapod.R | import org.mosad.teapod.R | ||||||
| import org.mosad.teapod.parser.AoDParser | import org.mosad.teapod.parser.AoDParser | ||||||
| import org.mosad.teapod.ui.components.MediaLinearLayout |  | ||||||
| import org.mosad.teapod.util.CustomAdapter | import org.mosad.teapod.util.CustomAdapter | ||||||
| import org.mosad.teapod.util.GUIMedia | import org.mosad.teapod.util.GUIMedia | ||||||
|  |  | ||||||
| @ -23,35 +18,27 @@ class LibraryFragment : Fragment() { | |||||||
|     private lateinit var adapter : CustomAdapter |     private lateinit var adapter : CustomAdapter | ||||||
|  |  | ||||||
|     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||||||
|         val root =  inflater.inflate(R.layout.fragment_library, container, false) |         return inflater.inflate(R.layout.fragment_library, container, false) | ||||||
|         return root |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |     override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||||||
|         super.onViewCreated(view, savedInstanceState) |         super.onViewCreated(view, savedInstanceState) | ||||||
|  |  | ||||||
|  |  | ||||||
|         adapter = CustomAdapter(requireContext(),layoutInflater, mediaList)//ArrayAdapter(requireContext(), R.layout.linear_media, R.id.text_title, mediaList) |         GlobalScope.launch { | ||||||
|  |  | ||||||
|         list_library.adapter = adapter |  | ||||||
|  |  | ||||||
|         text_dashboard.text = "Loading Animes ..." |  | ||||||
|  |  | ||||||
|         loadAnimeList() |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun loadAnimeList() = GlobalScope.launch { |  | ||||||
|  |  | ||||||
|             val parser = AoDParser() |             val parser = AoDParser() | ||||||
|             mediaList = parser.listAnime() |             mediaList = parser.listAnime() | ||||||
|  |  | ||||||
|         text_dashboard.text = "got ${mediaList.size} animes" |             println("setting adapter") | ||||||
|  |  | ||||||
|             withContext(Dispatchers.Main) { |             withContext(Dispatchers.Main) { | ||||||
|  |                 adapter = CustomAdapter(requireContext(), mediaList)//ArrayAdapter(requireContext(), R.layout.linear_media, R.id.text_title, mediaList) | ||||||
|  |  | ||||||
|  |                 list_library.adapter = adapter | ||||||
|                 adapter.notifyDataSetChanged() |                 adapter.notifyDataSetChanged() | ||||||
|             println("notifiyed") |             } | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
| @ -1,13 +0,0 @@ | |||||||
| package org.mosad.teapod.ui.library |  | ||||||
|  |  | ||||||
| import androidx.lifecycle.LiveData |  | ||||||
| import androidx.lifecycle.MutableLiveData |  | ||||||
| import androidx.lifecycle.ViewModel |  | ||||||
|  |  | ||||||
| class LibraryViewModel : ViewModel() { |  | ||||||
|  |  | ||||||
|     private val _text = MutableLiveData<String>().apply { |  | ||||||
|         value = "This is the library Fragment" |  | ||||||
|     } |  | ||||||
|     val text: LiveData<String> = _text |  | ||||||
| } |  | ||||||
| @ -9,14 +9,13 @@ import android.widget.ImageView | |||||||
| import android.widget.TextView | import android.widget.TextView | ||||||
| import com.bumptech.glide.Glide | import com.bumptech.glide.Glide | ||||||
| import org.mosad.teapod.R | import org.mosad.teapod.R | ||||||
|  | import org.mosad.teapod.ui.components.MediaLinearLayout | ||||||
|  |  | ||||||
| class CustomAdapter(context: Context, private val layoutInflater: LayoutInflater, private val media: ArrayList<GUIMedia>) : ArrayAdapter<GUIMedia>(context, R.layout.linear_media) { | class CustomAdapter(context: Context, private val media: ArrayList<GUIMedia>) : ArrayAdapter<GUIMedia>(context, R.layout.linear_media, media) { | ||||||
|  |  | ||||||
|     override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { |     override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { | ||||||
|         println("view") |  | ||||||
|  |  | ||||||
|         return if (convertView == null) { |         return if (convertView == null) { | ||||||
|             val guiMedia = layoutInflater.inflate(R.layout.linear_media, null) |             val guiMedia = LayoutInflater.from(context).inflate(R.layout.linear_media, parent, false) | ||||||
|  |  | ||||||
|             val textTitle = guiMedia.findViewById<TextView>(R.id.text_title) |             val textTitle = guiMedia.findViewById<TextView>(R.id.text_title) | ||||||
|             val imagePoster = guiMedia.findViewById<ImageView>(R.id.image_poster) |             val imagePoster = guiMedia.findViewById<ImageView>(R.id.image_poster) | ||||||
|  | |||||||
| @ -15,28 +15,4 @@ | |||||||
|         app:layout_constraintStart_toStartOf="parent" |         app:layout_constraintStart_toStartOf="parent" | ||||||
|         app:layout_constraintTop_toTopOf="parent" /> |         app:layout_constraintTop_toTopOf="parent" /> | ||||||
|  |  | ||||||
|     <ScrollView |  | ||||||
|         android:id="@+id/scroll_library" |  | ||||||
|         android:layout_width="match_parent" |  | ||||||
|         android:layout_height="match_parent" |  | ||||||
|         android:visibility="gone"> |  | ||||||
|  |  | ||||||
|         <LinearLayout |  | ||||||
|             android:id="@+id/linear_library" |  | ||||||
|             android:layout_width="match_parent" |  | ||||||
|             android:layout_height="wrap_content" |  | ||||||
|             android:orientation="vertical"> |  | ||||||
|  |  | ||||||
|             <TextView |  | ||||||
|                 android:id="@+id/text_dashboard" |  | ||||||
|                 android:layout_width="match_parent" |  | ||||||
|                 android:layout_height="wrap_content" |  | ||||||
|                 android:layout_marginStart="8dp" |  | ||||||
|                 android:layout_marginTop="8dp" |  | ||||||
|                 android:layout_marginEnd="8dp" |  | ||||||
|                 android:textAlignment="center" |  | ||||||
|                 android:textSize="20sp" /> |  | ||||||
|         </LinearLayout> |  | ||||||
|     </ScrollView> |  | ||||||
|  |  | ||||||
| </androidx.constraintlayout.widget.ConstraintLayout> | </androidx.constraintlayout.widget.ConstraintLayout> | ||||||
		Reference in New Issue
	
	Block a user