Skip to content

Commit

Permalink
color palette update, exceptions was fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Sep 18, 2022
1 parent 130788e commit a36e42a
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 59 deletions.
8 changes: 4 additions & 4 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ android {
defaultConfig {
applicationId "com.ethosa.ktc"
minSdk 21
targetSdk 32
versionCode 24
versionName "0.8.13"
targetSdk 33
versionCode 25
versionName "0.9.0"
ndk {
abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
}
Expand Down Expand Up @@ -39,19 +39,19 @@ android {
}

dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.github.bumptech.glide:glide:4.13.1'
implementation 'jp.wasabeef:glide-transformations:4.3.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.webkit:webkit:1.4.0'
implementation 'androidx.webkit:webkit:1.5.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ interface CollegeCallback : Callback {
* Calls on request failure
*/
override fun onFailure(call: Call, e: IOException) {
Log.e("CollegeAPI", e.message.toString())
Log.e("CollegeAPI", e.stackTraceToString())
}
}
26 changes: 23 additions & 3 deletions app/src/main/java/com/ethosa/ktc/ui/dialog/AppUpdater.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import com.ethosa.ktc.BuildConfig
Expand All @@ -15,8 +16,10 @@ import com.ethosa.ktc.college.CollegeApi
import com.ethosa.ktc.college.CollegeCallback
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import okhttp3.Call
import okhttp3.Response
import java.lang.Exception


/**
Expand Down Expand Up @@ -61,12 +64,18 @@ class AppUpdater(
.setPositiveButton(R.string.update_dialog_positive) { dialog, _ ->
try {
// Detect Google play market
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(Constants.GOOGLE_PLAY_MARKET_URL))
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse(Constants.GOOGLE_PLAY_MARKET_URL)
)
intent.`package` = Constants.GOOGLE_PLAY_PACKAGE
context.startActivity(intent)
} catch (notFound: ActivityNotFoundException) {
// Go to GitHub releases
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(Constants.GITHUB_RELEASES_URL))
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse(Constants.GITHUB_RELEASES_URL)
)
context.startActivity(intent)
}
dialog.dismiss()
Expand Down Expand Up @@ -100,7 +109,18 @@ class AppUpdater(
CollegeApi.fetchActualVersion(object : CollegeCallback {
override fun onResponse(call: Call, response: Response) {
val body = response.body?.string()
actualVersion = Gson().fromJson(body, ActualAppVersion::class.java)
try {
actualVersion = Gson().fromJson(body, ActualAppVersion::class.java)
} catch (e: JsonSyntaxException) {
return
} catch (e: Exception) {
context.runOnUiThread {
Toast.makeText(
context, R.string.toast_update_error, Toast.LENGTH_SHORT
).show()
}
return
}

if (!actualVersion!!.isActual())
context.runOnUiThread { showDialog() }
Expand Down
38 changes: 35 additions & 3 deletions app/src/main/java/com/ethosa/ktc/ui/fragments/GalleryFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.ethosa.ktc.Preferences
import com.ethosa.ktc.R
import com.ethosa.ktc.college.CollegeApi
import com.ethosa.ktc.college.CollegeCallback
import com.ethosa.ktc.college.gallery.Albums
import com.ethosa.ktc.databinding.FragmentGalleryBinding
import com.ethosa.ktc.ui.adapters.AlbumsPreviewAdapter
import com.ethosa.ktc.ui.decoration.SpacingItemDecoration
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import okhttp3.Call
import okhttp3.Response
import java.io.IOException
import java.lang.Exception

/**
* Provides albums behavior
Expand All @@ -37,7 +41,9 @@ class GalleryFragment(

_binding = FragmentGalleryBinding.inflate(inflater, container, false)

val layoutManager = StaggeredGridLayoutManager(spanCount, StaggeredGridLayoutManager.VERTICAL)
val layoutManager = StaggeredGridLayoutManager(
spanCount, StaggeredGridLayoutManager.VERTICAL
)
layoutManager.gapStrategy = StaggeredGridLayoutManager.GAP_HANDLING_NONE
binding.albumsList.layoutManager = layoutManager
binding.albumsList.setHasFixedSize(true)
Expand All @@ -62,7 +68,24 @@ class GalleryFragment(
override fun onResponse(call: Call, response: Response) {
// Parse JSON
val json = response.body?.string()
val albums = Gson().fromJson(json, Albums::class.java)
val albums: Albums
try {
albums = Gson().fromJson(json, Albums::class.java)
} catch (e: JsonSyntaxException) {
requireActivity().runOnUiThread {
Toast.makeText(
requireContext(), R.string.toast_gallery_error, Toast.LENGTH_SHORT
).show()
}
return
} catch (e: Exception) {
requireActivity().runOnUiThread {
Toast.makeText(
requireContext(), R.string.toast_unknown_error, Toast.LENGTH_SHORT
).show()
}
return
}
// Create animation object
val animate = ObjectAnimator.ofFloat(
_binding?.progressLoad, "alpha",
Expand All @@ -74,4 +97,13 @@ class GalleryFragment(
animate.start()
}
}

override fun onFailure(call: Call, e: IOException) {
super.onFailure(call, e)
requireActivity().runOnUiThread {
Toast.makeText(
requireContext(), R.string.toast_gallery_error, Toast.LENGTH_SHORT
).show()
}
}
}
38 changes: 36 additions & 2 deletions app/src/main/java/com/ethosa/ktc/ui/fragments/NewsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ethosa.ktc.Preferences
import com.ethosa.ktc.R
import com.ethosa.ktc.college.CollegeApi
import com.ethosa.ktc.college.CollegeCallback
import com.ethosa.ktc.college.news.LastNews
Expand All @@ -17,8 +19,11 @@ import com.ethosa.ktc.ui.adapters.NewsAdapter
import com.ethosa.ktc.ui.adapters.NewsStoriesAdapter
import com.ethosa.ktc.ui.decoration.SpacingItemDecoration
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import okhttp3.Call
import okhttp3.Response
import java.io.IOException
import java.lang.Exception

/**
* Provides working with KTC last news.
Expand All @@ -38,7 +43,9 @@ class NewsFragment : Fragment(), CollegeCallback {
binding.news.layoutManager = LinearLayoutManager(context)
binding.news.addItemDecoration(SpacingItemDecoration(0, 32))

binding.newsStories.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
binding.newsStories.layoutManager = LinearLayoutManager(
context, RecyclerView.HORIZONTAL, false
)
binding.newsStories.addItemDecoration(SpacingItemDecoration(16, 0))

// Fetch last news from college
Expand All @@ -61,7 +68,25 @@ class NewsFragment : Fragment(), CollegeCallback {
override fun onResponse(call: Call, response: Response) {
// Parse JSON
val jsonString = response.body?.string()
val news = Gson().fromJson(jsonString, LastNews::class.java)
val news: LastNews
try {
news = Gson().fromJson(jsonString, LastNews::class.java)
} catch (e: JsonSyntaxException) {
requireActivity().runOnUiThread {
Toast.makeText(
requireContext(), R.string.toast_news_error, Toast.LENGTH_SHORT
).show()
}
return
} catch (e: Exception) {
requireActivity().runOnUiThread {
Toast.makeText(
requireContext(), R.string.toast_unknown_error, Toast.LENGTH_SHORT
).show()
}
e.printStackTrace()
return
}
news.catch()
// Create animation object
val animate = ObjectAnimator.ofFloat(
Expand All @@ -78,4 +103,13 @@ class NewsFragment : Fragment(), CollegeCallback {
)
}
}

override fun onFailure(call: Call, e: IOException) {
super.onFailure(call, e)
requireActivity().runOnUiThread {
Toast.makeText(
requireContext(), R.string.toast_news_error, Toast.LENGTH_SHORT
).show()
}
}
}
Loading

0 comments on commit a36e42a

Please sign in to comment.