Skip to content

Commit

Permalink
actions: less warnings is more (fixes #3251) (#3254)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Mar 15, 2024
1 parent 0988ff0 commit 94927ef
Show file tree
Hide file tree
Showing 21 changed files with 81 additions and 113 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1418
versionName "0.14.18"
versionCode 1419
versionName "0.14.19"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity

abstract class BaseActivity : AppCompatActivity() {
public override fun onCreate(savedInstanceStat: Bundle?) {
super.onCreate(savedInstanceStat)
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

fun initActionBar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ abstract class BaseNewsFragment : BaseContainerFragment(), OnNewsItemClickListen

override fun onDestroy() {
super.onDestroy()
if (profileDbHandler != null) profileDbHandler.onDestory()
profileDbHandler.onDestory()
}

override fun showReply(news: RealmNews?, fromLogin: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ abstract class BaseResourceFragment : Fragment() {
.setTitle(R.string.download_suggestion)
alertDialogBuilder.setPositiveButton(R.string.download_selected) { _: DialogInterface?, _: Int ->
lv?.selectedItemsList?.let {
downloadFiles(db_myLibrary, it, settings)
downloadFiles(db_myLibrary, it)
}?.let { startDownload(it) }
}.setNeutralButton(R.string.download_all) { _: DialogInterface?, _: Int ->
startDownload(downloadAllFiles(db_myLibrary, settings))
startDownload(downloadAllFiles(db_myLibrary))
}.setNegativeButton(R.string.txt_cancel, null)
val alertDialog = alertDialogBuilder.create()
createListView(db_myLibrary, alertDialog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.ole.planet.myplanet.model.RealmStepExam
interface OnHomeItemClickListener {
fun openCallFragment(f: Fragment)
fun openLibraryDetailFragment(library: RealmMyLibrary?)
fun showRatingDialog(resource: String?, resource_id: String?, title: String?, listener: OnRatingChangeListener?)
fun showRatingDialog(type: String?, resource_id: String?, title: String?, listener: OnRatingChangeListener?)

fun sendSurvey(current: RealmStepExam?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ class Service(private val context: Context) {
.enqueue(object : Callback<MyPlanet?> {
override fun onResponse(call: Call<MyPlanet?>, response: Response<MyPlanet?>) {
preferences.edit()
.putInt("LastWifiID", NetworkUtils.getCurrentNetworkId(context)).commit()
.putInt("LastWifiID", NetworkUtils.getCurrentNetworkId(context)).apply()
if (response.body() != null) {
val p = response.body()
preferences.edit()
.putString("versionDetail", Gson().toJson(response.body())).commit()
.putString("versionDetail", Gson().toJson(response.body())).apply()
retrofitInterface.getApkVersion(Utilities.getApkVersionUrl(settings))
.enqueue(object : Callback<ResponseBody> {
override fun onResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class ChatDetailFragment : Fragment() {
mRealm = Realm.getDefaultInstance()
addConversationToChatHistory(mRealm, _id, query, chatResponse)
} finally {
if (mRealm != null && !mRealm.isClosed) {
if (::mRealm.isInitialized && !mRealm.isClosed) {
mRealm.close()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ class AdapterCourses(private val context: Context, private var courseList: List<
if (`object`.has("ratingByUser"))
if (ratingBar != null) {
ratingBar.rating = `object`["ratingByUser"].asInt.toFloat()
} else if (ratingBar != null) {
ratingBar.rating = 0f
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl
lateinit var dbService: DatabaseService
lateinit var mRealm: Realm
var courseId: String? = null
lateinit var currentCourse: RealmMyCourse
private lateinit var currentCourse: RealmMyCourse
lateinit var steps: List<RealmCourseStep?>
lateinit var userModel: RealmUserModel
var position = 0
Expand All @@ -62,7 +62,7 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl
super.onViewCreated(view, savedInstanceState)
fragmentTakeCourseBinding.tvCourseTitle.text = currentCourse.courseTitle
steps = getSteps(mRealm, courseId)
if (steps == null || steps.isEmpty()) {
if (steps.isEmpty()) {
fragmentTakeCourseBinding.nextStep.visibility = View.GONE
fragmentTakeCourseBinding.previousStep.visibility = View.GONE
}
Expand Down Expand Up @@ -108,8 +108,8 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl
fragmentTakeCourseBinding.btnRemove.visibility = View.GONE
}
createActivity(mRealm, userModel, currentCourse)
fragmentTakeCourseBinding.tvStep.text = "${getString(R.string.step)} 0/${steps?.size ?: 0}"
if (steps != null) fragmentTakeCourseBinding.courseProgress.max = steps.size
fragmentTakeCourseBinding.tvStep.text = "${getString(R.string.step)} 0/${steps.size}"
fragmentTakeCourseBinding.courseProgress.max = steps.size
val i = getCurrentProgress(steps, mRealm, userModel.id, courseId)
if (i < steps.size) fragmentTakeCourseBinding.courseProgress.secondaryProgress = i + 1
fragmentTakeCourseBinding.courseProgress.progress = i
Expand Down Expand Up @@ -172,7 +172,7 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl
when (view.id) {
R.id.next_step -> {
if (isValidClickRight) {
fragmentTakeCourseBinding.viewPagerCourse.currentItem = fragmentTakeCourseBinding.viewPagerCourse.currentItem + 1
fragmentTakeCourseBinding.viewPagerCourse.currentItem += 1
fragmentTakeCourseBinding.previousStep.visibility = View.VISIBLE
}
onClickNext()
Expand All @@ -181,7 +181,7 @@ class TakeCourseFragment : Fragment(), ViewPager.OnPageChangeListener, View.OnCl
R.id.previous_step -> {
onClickPrevious()
if (isValidClickLeft) {
fragmentTakeCourseBinding.viewPagerCourse.currentItem = fragmentTakeCourseBinding.viewPagerCourse.currentItem - 1
fragmentTakeCourseBinding.viewPagerCourse.currentItem -= 1
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EnterpriseCalendarFragment : BaseTeamFragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
): View {
fragmentEnterpriseCalendarBinding = FragmentEnterpriseCalendarBinding.inflate(inflater, container, false)
start = Calendar.getInstance()
end = Calendar.getInstance()
Expand Down Expand Up @@ -79,8 +79,6 @@ class EnterpriseCalendarFragment : BaseTeamFragment() {
Utilities.toast(activity, getString(R.string.title_is_required))
} else if (desc.isEmpty()) {
Utilities.toast(activity, getString(R.string.description_is_required))
} else if (start == null) {
Utilities.toast(activity, getString(R.string.start_time_is_required))
} else {
if (!mRealm.isInTransaction) mRealm.beginTransaction()
val meetup =
Expand All @@ -90,7 +88,7 @@ class EnterpriseCalendarFragment : BaseTeamFragment() {
meetup.meetupLocation = loc
meetup.creator = user?.id
meetup.startDate = start.timeInMillis
if (end != null) meetup.endDate = end.timeInMillis
meetup.endDate = end.timeInMillis
meetup.endTime = addMeetupBinding.tvEndTime.text.toString()
meetup.startTime = addMeetupBinding.tvStartTime.text.toString()
val rb = addMeetupBinding.rgRecuring.findViewById<RadioButton>(addMeetupBinding.rgRecuring.checkedRadioButtonId)
Expand All @@ -117,7 +115,7 @@ class EnterpriseCalendarFragment : BaseTeamFragment() {
date!!.set(Calendar.YEAR, year)
date.set(Calendar.MONTH, monthOfYear)
date.set(Calendar.DAY_OF_MONTH, dayOfMonth)
if (view != null) view.text = TimeUtils.formatDate(date.timeInMillis, "yyyy-MM-dd")
view.text = TimeUtils.formatDate(date.timeInMillis, "yyyy-MM-dd")
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show()

}
Expand Down Expand Up @@ -170,11 +168,11 @@ class EnterpriseCalendarFragment : BaseTeamFragment() {
override fun create(view: View) = DayViewContainer(view)
override fun bind(container: DayViewContainer, day: CalendarDay) {
container.textView.text = day.date.dayOfMonth.toString()
var c = Calendar.getInstance()
val c = Calendar.getInstance()
c.set(Calendar.YEAR, day.date.year)
c.set(Calendar.MONTH, day.date.monthValue - 1)
c.set(Calendar.DAY_OF_MONTH, day.date.dayOfMonth)
var event = getEvent(c.timeInMillis)
val event = getEvent(c.timeInMillis)
if (day.owner == DayOwner.THIS_MONTH) {
container.textView.setTextColor(Color.BLACK)
} else {
Expand Down Expand Up @@ -207,12 +205,12 @@ class EnterpriseCalendarFragment : BaseTeamFragment() {
}

private fun getTimeMills(time: Long, end: Boolean): Long {
var c = Calendar.getInstance()
val c = Calendar.getInstance()
c.timeInMillis = time
c.set(Calendar.MINUTE, if (end) 59 else 0)
c.set(Calendar.HOUR, if (end) 23 else 0)
c.set(Calendar.SECOND, if (end) 59 else 0)
return c.timeInMillis;
return c.timeInMillis
}

class DayViewContainer(view: View) : ViewContainer(view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class FeedbackFragment : DialogFragment(), View.OnClickListener {
databaseService = DatabaseService(requireActivity())
mRealm = databaseService.realmInstance
model = UserProfileDbHandler(requireContext()).userModel!!
user = if (model != null) { model.name }
else { "Anonymous" }
user = model.name
fragmentFeedbackBinding.btnSubmit.setOnClickListener(this)
fragmentFeedbackBinding.btnCancel.setOnClickListener(this)
return fragmentFeedbackBinding.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class MyPersonalsFragment : Fragment(), OnSelectedMyPersonal {

override fun onDestroy() {
super.onDestroy()
if (mRealm != null && !mRealm.isClosed) mRealm.close()
if (::mRealm.isInitialized && !mRealm.isClosed) {
mRealm.close()
}
}

override fun onUpload(personal: RealmMyPersonal?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.util.Date
import java.util.UUID

class NewsDetailActivity : BaseActivity() {
lateinit var activityNewsDetailBinding: ActivityNewsDetailBinding
private lateinit var activityNewsDetailBinding: ActivityNewsDetailBinding
var news: RealmNews? = null
lateinit var realm: Realm
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -47,7 +47,7 @@ class NewsDetailActivity : BaseActivity() {
newsLog.androidId = NetworkUtils.getUniqueIdentifier()
newsLog.type = "news"
newsLog.time = Date().time
if (user != null) newsLog.userId = userId
newsLog.userId = userId
}
initViews()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SendSurveyFragment : BaseDialogFragment() {
.equalTo("parentId", if (!TextUtils.isEmpty(exam!!.courseId)) id + "@" + exam.courseId else id)
.sort("lastUpdateTime", Sort.DESCENDING).equalTo("status", "pending").findFirst()
sub = createSubmission(sub, mRealm)
sub!!.parentId = if (!TextUtils.isEmpty(exam.courseId)) id + "@" + exam.courseId else id
sub.parentId = if (!TextUtils.isEmpty(exam.courseId)) id + "@" + exam.courseId else id
sub.userId = userId
sub.type = "survey"
sub.status = "pending"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack
Utilities.log("LAST SSID $id")
val wifiManager = applicationContext.getSystemService(WIFI_SERVICE) as WifiManager
val netId: Int
if (wifiManager == null) {
Utilities.toast(this, getString(R.string.unable_to_connect_to_planet_wifi))
return
}
for (tmp in wifiManager.configuredNetworks) {
if (tmp.networkId > -1 && tmp.networkId == id) {
netId = tmp.networkId
Expand Down
20 changes: 9 additions & 11 deletions app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,15 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
progressDialog?.show()
}

override fun onSyncFailed(s: String?) {
override fun onSyncFailed(msg: String?) {
if (::syncIconDrawable.isInitialized) {
syncIconDrawable = syncIcon.drawable as AnimationDrawable
syncIconDrawable.stop()
syncIconDrawable.selectDrawable(0)
syncIcon.invalidateDrawable(syncIconDrawable)
}
runOnUiThread {
showAlert(this@SyncActivity, getString(R.string.sync_failed), s)
showAlert(this@SyncActivity, getString(R.string.sync_failed), msg)
showWifiSettingDialog(this@SyncActivity)
}
}
Expand Down Expand Up @@ -745,7 +745,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
builder.setNegativeButton("cancel") { dialog: DialogInterface, _: Int -> dialog.dismiss() }
builder.setPositiveButton("continue") { dialog: DialogInterface, _: Int ->
dialog.dismiss()
val model = mRealm.copyFromRealm(createGuestUser(username, mRealm, settings))
val model = createGuestUser(username, mRealm, settings)?.let { mRealm.copyFromRealm(it) }
if (model == null) {
Utilities.toast(this, getString(R.string.unable_to_login))
} else {
Expand Down Expand Up @@ -988,9 +988,7 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long) {
if (position > 0) {
val selectedTeam = teams[position - 1]
if (selectedTeam != null) {
selectedTeamId = selectedTeam._id
}
selectedTeamId = selectedTeam._id
}
}

Expand Down Expand Up @@ -1092,13 +1090,13 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
})
}

override fun onSuccess(s: String?) {
override fun onSuccess(success: String?) {
Utilities.log("Sync completed ")
if (progressDialog?.isShowing == true && s?.contains("Crash") == true) {
if (progressDialog?.isShowing == true && success?.contains("Crash") == true) {
progressDialog?.dismiss()
}
if (::btnSignIn.isInitialized) {
showSnack(btnSignIn, s)
showSnack(btnSignIn, success)
}
settings.edit().putLong("lastUsageUploaded", Date().time).apply()
if (::lblLastSyncDate.isInitialized) {
Expand Down Expand Up @@ -1139,13 +1137,13 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
bManager.registerReceiver(broadcastReceiver, intentFilter)
}

override fun onError(msg: String, block: Boolean) {
override fun onError(msg: String, blockSync: Boolean) {
Utilities.toast(this, msg)
if (msg.startsWith("Config")) {
settingDialog(this)
}
progressDialog?.dismiss()
if (!block) continueSyncProcess(forceSync = false, isSync = true) else {
if (!blockSync) continueSyncProcess(forceSync = false, isSync = true) else {
syncIconDrawable.stop()
syncIconDrawable.selectDrawable(0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ class AchievementFragment : BaseContainerFragment() {
fragmentAchievementBinding.rvOtherInfo.adapter = AdapterOtherInfo(MainApplication.context, achievement!!.getreferences()!!)
}
aRealm.addChangeListener {
if (fragmentAchievementBinding.llAchievement != null)
fragmentAchievementBinding.llAchievement.removeAllViews()
fragmentAchievementBinding.llAchievement.removeAllViews()
createAchievementList()
}
} else {
Expand Down
Loading

0 comments on commit 94927ef

Please sign in to comment.