فهرست منبع

removed default json

sirekanian 3 سال پیش
والد
کامیت
6c4a4e2d8a

+ 1 - 1
app/src/main/java/com/sirekanian/acf/App.kt

@@ -8,5 +8,5 @@ import com.sirekanian.acf.data.local.Database
 
 class App : Application() {
     private val db by lazy { Room.databaseBuilder(this, Database::class.java, "database").build() }
-    val repository: Repository by lazy { RepositoryImpl(resources, db.warmongerDao()) }
+    val repository: Repository by lazy { RepositoryImpl(db.warmongerDao()) }
 }

+ 2 - 2
app/src/main/java/com/sirekanian/acf/MainActivity.kt

@@ -36,9 +36,9 @@ class MainActivity : ComponentActivity() {
             val hasData by derivedStateOf { data.isNotEmpty() }
             LaunchedEffect(Unit) {
                 try {
-                    presenter.initData()
+                    presenter.updateData()
                 } catch (exception: Exception) {
-                    Log.e("Warmongr", "Cannot initialize data", exception)
+                    Log.e("Warmongr", "Cannot update data", exception)
                 }
             }
             BackHandler(enabled = state.search.isOpened) {

+ 2 - 5
app/src/main/java/com/sirekanian/acf/MainPresenter.kt

@@ -16,7 +16,7 @@ fun createPresenter(app: App, state: MainState): MainPresenter =
 
 interface MainPresenter {
     fun observeData(): Flow<List<Warmonger>>
-    suspend fun initData()
+    suspend fun updateData()
 }
 
 class MainPresenterImpl(
@@ -31,11 +31,8 @@ class MainPresenterImpl(
             repository.observeAll()
         }
 
-    override suspend fun initData() =
+    override suspend fun updateData() =
         withContext(IO) {
-            if (!repository.hasData()) {
-                repository.initLocal()
-            }
             while (true) {
                 repository.updateFromRemote(state.progress)
                 delay(UPDATE_PERIOD)

+ 0 - 17
app/src/main/java/com/sirekanian/acf/data/Repository.kt

@@ -1,29 +1,21 @@
 package com.sirekanian.acf.data
 
-import android.content.res.Resources
 import android.database.sqlite.SQLiteException
 import com.sirekanian.acf.ProgressState
-import com.sirekanian.acf.R
 import com.sirekanian.acf.data.local.WarmongerDao
 import com.sirekanian.acf.data.local.WarmongerEntity
-import com.sirekanian.acf.data.remote.WarmongerDto
 import com.sirekanian.acf.data.remote.getWarmongers
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.catch
 import kotlinx.coroutines.flow.map
-import kotlinx.serialization.decodeFromString
-import kotlinx.serialization.json.Json
 
 interface Repository {
     fun observeAll(): Flow<List<Warmonger>>
     fun observeByQuery(query: String): Flow<List<Warmonger>>
-    suspend fun hasData(): Boolean
-    suspend fun initLocal()
     suspend fun updateFromRemote(progressState: ProgressState)
 }
 
 class RepositoryImpl(
-    private val resources: Resources,
     private val dao: WarmongerDao,
 ) : Repository {
 
@@ -42,15 +34,6 @@ class RepositoryImpl(
             }
         }
 
-    override suspend fun hasData(): Boolean =
-        dao.hasData()
-
-    override suspend fun initLocal() {
-        val content = resources.openRawResource(R.raw.default1).bufferedReader().readText()
-        val local = Json.decodeFromString<List<WarmongerDto>>(content)
-        saveToLocal(local.map(Warmonger::fromDto))
-    }
-
     override suspend fun updateFromRemote(progressState: ProgressState) {
         try {
             progressState.show()

+ 0 - 3
app/src/main/java/com/sirekanian/acf/data/local/WarmongerDao.kt

@@ -17,9 +17,6 @@ interface WarmongerDao {
     @Query("SELECT * FROM WarmongerEntity WHERE WarmongerEntity MATCH :query LIMIT $LIMIT")
     fun observeByQuery(query: String): Flow<List<WarmongerEntity>>
 
-    @Query("SELECT count(1) FROM WarmongerEntity LIMIT 1")
-    suspend fun hasData(): Boolean
-
     @Query("DELETE FROM WarmongerEntity")
     suspend fun deleteAll()
 

+ 0 - 82
app/src/main/res/raw/default1.json

@@ -1,82 +0,0 @@
-[
-  {
-    "0": "Абазалиева Лариса Хасанбиевна",
-    "1": "Abazalieva Larisa Khasanbievna",
-    "2": "23.08.1967",
-    "3": "female",
-    "4": "Chairman of the Election Commission of the Karachay-Cherkess Republic. Head of the state body responsible for supporting the existing political regime in Russia through electoral fraud.",
-    "5": "Election fraud organizers\nHeads of the Central Election Commission and local \nelection commissions"
-  },
-  {
-    "0": "Абакаров Хизри Магомедович",
-    "1": "Abakarov Khizri Magomedovich",
-    "2": "28.06.1960",
-    "3": "male",
-    "4": "Member of the State Duma of the Russian Federation. This state body is responsible for political and legal support of the aggressive war against Ukraine.",
-    "5": "Members of Parliament and Senate\nState Duma"
-  },
-  {
-    "0": "Абашкин Игорь Анатольевич",
-    "1": "Abashkin Igor Anatolievich",
-    "2": "02.03.1970",
-    "3": "male",
-    "4": "Head of the Directorate of the Federal Service of the National Guard Troops of the Russian Federation for the Ulyanovsk Oblast. Heads special military units in the territory under his jurisdiction, which carried out the dispersal of peaceful protests against the Russian invasion of Ukraine and the political regime in Russia.",
-    "5": "Key ‘siloviki’ (security forces) figure\nNational Guard of Russia"
-  },
-  {
-    "0": "Аббазов Ильшат Загфярович",
-    "1": "Abbazov Ilshat Zagfyarovich",
-    "2": "",
-    "3": "male",
-    "4": "Judge of the Moscow City Court. Responsible for the criminal prosecution of citizens of the Russian Federation who oppose the current political regime in Russia.",
-    "5": "Organizers of political repressions\nJudges, prosecutors, state investigators, etc"
-  },
-  {
-    "0": "Абдрахимов Раиф Рамазанович",
-    "1": "Abdrakhimov Raif Ramazanovich",
-    "2": "13.10.1969",
-    "3": "male",
-    "4": "Deputy Prime Minister of the Government of the Republic of Bashkortostan. Manages a regional state body of the Russian Federation that supports or implements actions or policies that undermine or threaten the territorial integrity, sovereignty and independence of Ukraine.",
-    "5": "Key Local Government Officials \nVice-Governors"
-  },
-  {
-    "0": "Абдул-Кадыров Шарпудди Муайдович",
-    "1": "Abdul-Kadyrov Sharpuddi Muaydovich",
-    "2": "05.10.1965",
-    "3": "male",
-    "4": "Prosecutor of the Chechen Republic. Head of the federal state body that provides legal protection for the Russian political regime and refused to protect the rule of law in the context of the invasion of Russian troops in Ukraine.",
-    "5": "Key ‘siloviki’ (security forces) figure \nProsecutor’s Office"
-  },
-  {
-    "0": "Абдулаев М. М.",
-    "1": "Abdulaev M. M.",
-    "2": "",
-    "3": "male",
-    "4": "Investigator for particularly important cases of the first department of investigation of particularly important cases (on crimes against the person and public safety) of the Investigation Department of the RF IC in the Penza Oblast. Involved in the fabrication of the “FBK case”",
-    "5": "Organizers of political repressions\nJudges, prosecutors, state investigators, etc"
-  },
-  {
-    "0": "Абдуллазянов Эдвард Юнусович",
-    "1": "Abdullazyanov Edward Yunusovich",
-    "2": "08.04.1957",
-    "3": "male",
-    "4": "Rector of Kazan State Power Engineering University. Signed an open letter of university rectors expressing support for the decision of the President of Russia to launch a military operation against Ukraine.",
-    "5": "Warmongers\nEducators"
-  },
-  {
-    "0": "Абдулмуслимов Абдулмуслим Мухудинович",
-    "1": "Abdulmuslimov Abdulmuslim Mukhaudinovich",
-    "2": "01.04.1960",
-    "3": "male",
-    "4": "Chairman of the Government Republic of Dagestan. Manages a regional state body of the Russian Federation that supports or implements actions or policies that undermine or threaten the territorial integrity, sovereignty and independence of Ukraine.",
-    "5": "Key Local Government Officials \nVice-Governors"
-  },
-  {
-    "0": "АБДУЛХАЛИМОВ МАГОМЕД СУЛТАНОВИЧ",
-    "1": "Abdulkhalimov Magomed Sultanovich",
-    "2": "02.12.1976",
-    "3": "Male",
-    "4": "Deputy Minister of Labor and Social Protection of the Russian Federation. Manages a state body of the Russian Federation, which supports or implements actions or policies that undermine or threaten the territorial integrity, sovereignty and independence of Ukraine.",
-    "5": "Senior Federal Officials\nExecutive branch and presidential administration employees"
-  }
-]

+ 0 - 7
upd.sh

@@ -1,7 +0,0 @@
-#!/usr/bin/env bash
-
-URL="https://sirekanian.github.io/warmongers.json"
-OUTPUT="app/src/main/res/raw/default1.json"
-COUNT="10"
-
-wget -qO- "$URL" | jq ".[0:$COUNT]" >"$OUTPUT"