Skip to content

Commit

Permalink
Done App
Browse files Browse the repository at this point in the history
  • Loading branch information
daniilkofficial committed Aug 3, 2022
1 parent c076f00 commit 7669770
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 163 deletions.
5 changes: 1 addition & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
android:supportsRtl="true"
android:theme="@style/Theme.StepikDevMobApp"
android:usesCleartextTraffic="true">
<activity
android:name=".SecondActivity"
android:exported="false" />

<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>
</activity>
Expand Down
11 changes: 2 additions & 9 deletions app/src/main/java/com/daniilk/stepikdevmobapp/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ class App : Application() {
override fun onCreate() {
super.onCreate()

// Realm инициализация, чтение в UI потоке, миграция и конфигурация
Realm.init(this)
val realmBuilder = RealmConfiguration.Builder()
.allowWritesOnUiThread(true)
.schemaVersion(1)
.deleteRealmIfMigrationNeeded()
.deleteRealmIfMigrationNeeded() // мигрирование изменний БД
val realmConfiguration = realmBuilder.build()
Realm.setDefaultConfiguration(realmConfiguration)

// getSharedPreferences("name", 0)
// .edit()
// .putString("zzz", "xx")
// .apply()
//
// getSharedPreferences("name", 0)
// .getString("zzz", "")

}
}
77 changes: 5 additions & 72 deletions app/src/main/java/com/daniilk/stepikdevmobapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import io.realm.RealmList
import io.realm.RealmObject

class MainActivity : AppCompatActivity() {
// private lateinit var launcher: ActivityResultLauncher<Intent>
// private lateinit var linearList: LinearLayout
// private lateinit var textView: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -37,26 +34,13 @@ class MainActivity : AppCompatActivity() {
// commitAllowingStateLoss - допускающая потерю состояния

}
// linearList = findViewById(R.id.linearList)
// launcher =
// registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
// if (result.resultCode == RESULT_OK)
// textView.text = result.data?.getStringExtra("text")
// }

// val i = Intent(this, SecondActivity::class.java)
// i.putExtra("text", textView.text)
// launcher.launch(i)

// Как нельзя делать: AsyncTask(doInBackground,onPostExecute) и Thread(run, runOnUiThread)
// варианты .flatMap { Observable.create<String> {} }.zipWith(Observable.create<String> {})

}

// Отображение статьи
fun showArticle(url: String) {
val bundle = Bundle()
bundle.putString("url", url)
val fragment = SecondFragment()
val fragment = WebFragment()
fragment.arguments = bundle

val frame2 = findViewById<View>(R.id.fragment_place2)
Expand All @@ -81,33 +65,6 @@ class MainActivity : AppCompatActivity() {
startService(intent)
}

// private fun showLinearLayout(feedList: ArrayList<FeedItem>) {
// val inflate = layoutInflater
// for (f in feedList) {
// val view = inflate.inflate(R.layout.list_item, linearList, false)
// val txtTitle = view.findViewById<TextView>(R.id.txtTitle)
// txtTitle.text = f.title
// linearList.addView(view)
// }
//
// }
//
// private fun showListView(feedList: ArrayList<FeedItem>) {
// listView.adapter = Adapter(feedList)
// }


// override fun onConfigurationChanged(newConfig: Configuration) {
// super.onConfigurationChanged(newConfig)
// }
//
// override fun onSaveInstanceState(outState: Bundle) {
// super.onSaveInstanceState(outState)
// }
//
// override fun onDestroy() {
// super.onDestroy()
// }

companion object {
internal const val TAG = "MainActivity"
Expand Down Expand Up @@ -138,30 +95,6 @@ open class FeedItem(
var guid: String = ""
) : RealmObject()

/* class Adapter(private val items: ArrayList<FeedItem>) : BaseAdapter() {
override fun getCount(): Int {
return items.size
}
override fun getItem(position: Int): Any {
return items[position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, converterView: View?, parent: ViewGroup?): View {
val inflater = LayoutInflater.from(parent!!.context)
val view = converterView ?: inflater.inflate(R.layout.list_item, parent, false)
val txtTitle = view.findViewById<TextView>(R.id.txtTitle)
val item = getItem(position) as FeedItem
txtTitle.text = item.title
return view
}
} */

class RecAdapter(private val items: RealmList<FeedItem>) :
RecyclerView.Adapter<RecAdapter.RecHolder>() {

Expand Down Expand Up @@ -197,15 +130,15 @@ class RecAdapter(private val items: RealmList<FeedItem>) :
val thumbURI: String = item.thumbnail
try {
Picasso.with(imgThumb.context).load(thumbURI).into(imgThumb)
} catch (e: Exception) {
} catch (e: Exception) { // При пустой картинке или ошибке
Log.e("ImgLoadingError", e.message ?: "null")
val defaultThumbURI: String =
val defaultThumbURI =
"https://img3.akspic.ru/previews/8/7/7/6/6/166778/166778-spongebob-360x640.jpg"
Picasso.with(imgThumb.context).load(defaultThumbURI).into(imgThumb)
}

itemView.setOnClickListener {
// (itemView.context as MainActivity).showArticle(item.link)
(itemView.context as MainActivity).showArticle(item.link)
(itemView.context as MainActivity).playMusic(item.guid)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,12 @@ class MainFragment : Fragment(), LifecycleObserver {
private lateinit var recyclerView: RecyclerView
private var request: Disposable? = null


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val param = arguments?.getString("param")
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.activity_main, container, false)
val view = inflater.inflate(R.layout.fragment_main, container, false)

recyclerView = view.findViewById(R.id.recyclerView)

Expand All @@ -42,7 +36,6 @@ class MainFragment : Fragment(), LifecycleObserver {
super.onActivityCreated(savedInstanceState)

val o =
// createRequest("https://api.rss2json.com/v1/api.json?rss_url=http%3A%2F%2Ffeeds.bbci.co.uk%2Fnews%2Frss.xml")
createRequest("https://api.rss2json.com/v1/api.json?rss_url=http%3A%2F%2Ffeeds.twit.tv%2Fbrickhouse.xml")
.map { Gson().fromJson(it, FeedApi::class.java) }
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/java/com/daniilk/stepikdevmobapp/PlayService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ class PlayService : Service() {
var player: MediaPlayer? = null
var notification: NotificationCompat.Builder? = null

// вызод при создании 1 раз
override fun onCreate() {
super.onCreate()
}

// Запуск
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent?.action == "stop") {
player?.stop()
Expand Down Expand Up @@ -104,13 +100,12 @@ class PlayService : Service() {
return START_NOT_STICKY
}

// уничтожение
override fun onDestroy() {
player?.stop()
super.onDestroy()
}

// запущен или подключен
// Без подключения к запущеному
override fun onBind(intent: Intent?): IBinder? {
return null
}
Expand Down
26 changes: 0 additions & 26 deletions app/src/main/java/com/daniilk/stepikdevmobapp/SecondActivity.kt

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/java/com/daniilk/stepikdevmobapp/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.reactivex.Observable
import java.net.HttpURLConnection
import java.net.URL

fun createRequest(url: String): Observable<String> = Observable.create<String> {
fun createRequest(url: String): Observable<String> = Observable.create {
val urlConnection = URL(url).openConnection() as HttpURLConnection
try {
urlConnection.connect() // само обращение в сеть
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.view.ViewGroup
import android.webkit.WebView
import androidx.fragment.app.Fragment

class SecondFragment : Fragment() {
class WebFragment : Fragment() {
private lateinit var url: String
private lateinit var webView: WebView

Expand All @@ -22,7 +22,7 @@ class SecondFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = inflater.inflate(R.layout.second_fragment, container, false)
val view = inflater.inflate(R.layout.fragment_web, container, false)
webView = view.findViewById(R.id.webView)
return view
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout-land/activity_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<FrameLayout
android:id="@+id/fragment_place2"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
9 changes: 5 additions & 4 deletions app/src/main/res/layout/activity_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/fragment_place"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<FrameLayout
android:id="@+id/fragment_place"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
24 changes: 0 additions & 24 deletions app/src/main/res/layout/activity_second.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent" />
</FrameLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/layout/list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:orientation="horizontal">

<ImageView
android:contentDescription="@string/image_article"
android:id="@+id/imgThumb"
android:layout_width="100dp"
android:layout_height="100dp"
Expand All @@ -24,8 +25,8 @@
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEXT"
android:lines="1"
android:text="TEXT"
android:textSize="18sp"
android:textStyle="bold" />

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">StepikDevMobApp</string>
<string name="app_name">Stepik Music App</string>
<string name="image_article">Image article</string>
<!-- <string name="app_name">StepikDevMobApp</string>-->
</resources>

0 comments on commit 7669770

Please sign in to comment.