-
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.
* primitive surfing * navigation to Nihil * created constant class
- Loading branch information
1 parent
4871edc
commit b71c9b8
Showing
6 changed files
with
129 additions
and
50 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 @@ | ||
[{"text":"Eсли вы здесь, значит, вы добрались до таксона, который ещё не был добавлен в наш справочник", "to":1}, {"text":"Вы можете помочь нам это сделать https://github.com/SomeAnonimCoder/TheBigMayevsky", "to":1}] |
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,72 @@ | ||
package msu.ug | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import android.widget.ListView | ||
import android.widget.SimpleAdapter | ||
import androidx.fragment.app.ListFragment | ||
import org.json.JSONArray | ||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
import java.lang.StringBuilder | ||
|
||
class ChoiceFragment(private val actContext: Context) : ListFragment() { | ||
private val storage = Storage(actContext) | ||
private val toIndices = ArrayList<Int>() | ||
private val taxons = ArrayList<String>() | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
|
||
val from = arrayOf(Const.MAP_TEXT_KEY) | ||
val to = intArrayOf(android.R.id.text1) | ||
val displayData = ArrayList<Map<String, Any>>() | ||
updateDisplayData(displayData) | ||
val listAdapter = SimpleAdapter(context, displayData, android.R.layout.simple_list_item_1, from, to) | ||
setListAdapter(listAdapter) | ||
storage.addSwitchListener { | ||
updateDisplayData(displayData) | ||
listAdapter.notifyDataSetChanged() | ||
} | ||
} | ||
|
||
override fun onListItemClick(l: ListView?, v: View?, position: Int, id: Long) { | ||
super.onListItemClick(l, v, position, id) | ||
if (toIndices[position] == 0) { | ||
storage.appendPath(taxons[position]) | ||
storage.currentChoise = 1 | ||
} else { | ||
storage.currentChoise = toIndices[position] | ||
} | ||
|
||
} | ||
|
||
private fun getPlainText(statementFile : String) : String { | ||
val statementStream = actContext.assets.open(statementFile) | ||
val br = BufferedReader(InputStreamReader(statementStream)) | ||
var line : String? = br.readLine() | ||
val sb = StringBuilder() | ||
|
||
while (line != null) { | ||
sb.append(line) | ||
line = br.readLine() | ||
} | ||
|
||
return sb.toString() | ||
} | ||
|
||
private fun updateDisplayData(displayData: ArrayList<Map<String, Any>>) { | ||
val file = storage.getPath().joinToString("/") + "/" + storage.currentChoise.toString() | ||
val arr = JSONArray(getPlainText(file)) | ||
toIndices.clear() | ||
displayData.clear() | ||
(0 until arr.length()).forEach {i -> | ||
val map = HashMap<String, Any>() | ||
val thesa = arr.getJSONObject(i) | ||
map[Const.MAP_TEXT_KEY] = thesa.getString(Const.JSON_TEXT_KEY) | ||
toIndices.add(thesa.getInt(Const.TO_KEY)) | ||
taxons.add(thesa.optString(Const.TAXON_KEY, Const.DEFAULT_TAXON)) | ||
displayData.add(map) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
package msu.ug | ||
|
||
class Const { | ||
companion object { | ||
const val CUR_CHOICE_KEY = "current_choise" | ||
const val PATH_LEN_KEY = "path_len" | ||
|
||
const val DEFAULT_TAXON = "Nihil" | ||
|
||
const val MAP_TEXT_KEY = "text" | ||
const val JSON_TEXT_KEY = "text" | ||
const val TO_KEY = "to" | ||
const val TAXON_KEY = "taxon" | ||
|
||
const val SP_NAME = "my_shared_preferences" | ||
|
||
fun folderKey(folderIndex : Int) : String { | ||
return "folder_$folderIndex" | ||
} | ||
} | ||
} |
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