Skip to content

Commit

Permalink
feat openMF#199: added network change receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
yashraj-01 committed Dec 9, 2020
1 parent 1766684 commit 33235e9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,36 @@ package org.mifos.mobile.cn.ui.mifos
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.os.Handler
import com.google.android.material.navigation.NavigationView
import androidx.core.view.GravityCompat
import androidx.appcompat.app.ActionBarDrawerToggle
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.core.view.GravityCompat
import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.activity_main.*
import org.mifos.mobile.cn.R
import org.mifos.mobile.cn.data.local.PreferencesHelper
import org.mifos.mobile.cn.ui.base.MifosBaseActivity
import org.mifos.mobile.cn.ui.mifos.dashboard.DashboardFragment
import org.mifos.mobile.cn.ui.mifos.login.LoginActivity
import org.mifos.mobile.cn.ui.utils.MaterialDialog
import javax.inject.Inject
import kotlinx.android.synthetic.main.activity_main.*
import org.mifos.mobile.cn.enums.AccountType
import org.mifos.mobile.cn.ui.base.MifosBaseActivity
import org.mifos.mobile.cn.ui.mifos.aboutus.AboutUsActivity
import org.mifos.mobile.cn.ui.mifos.customerAccounts.CustomerAccountFragment
import org.mifos.mobile.cn.ui.mifos.loanApplication.loanActivity.LoanApplicationActivity
import org.mifos.mobile.cn.ui.mifos.dashboard.DashboardFragment
import org.mifos.mobile.cn.ui.mifos.login.LoginActivity
import org.mifos.mobile.cn.ui.mifos.products.ProductFragment
import org.mifos.mobile.cn.ui.mifos.recentTransactions.RecentTransactionsFragment
import org.mifos.mobile.cn.ui.mifos.settings.SettingsFragment
import org.mifos.mobile.cn.ui.utils.CircularImageView
import org.mifos.mobile.cn.ui.utils.MaterialDialog
import org.mifos.mobile.cn.ui.utils.NetworkChangeReceiver
import org.mifos.mobile.cn.ui.utils.Toaster
import android.widget.Toast
import javax.inject.Inject


class DashboardActivity : MifosBaseActivity(), View.OnClickListener, NavigationView.OnNavigationItemSelectedListener {

Expand All @@ -54,6 +56,14 @@ class DashboardActivity : MifosBaseActivity(), View.OnClickListener, NavigationV

replaceFragment(DashboardFragment.newInstance(), false, R.id.container)

registerNetworkRegister()

}

fun registerNetworkRegister() {
val filter = IntentFilter()
filter.addAction("android.net.conn.CONNECTIVITY_CHANGE")
registerReceiver(NetworkChangeReceiver(), filter)
}


Expand Down Expand Up @@ -173,9 +183,9 @@ class DashboardActivity : MifosBaseActivity(), View.OnClickListener, NavigationV
replaceFragment(ProductFragment.Companion.newInstance(), true,
R.id.container)
}
R.id.item_recent_transactions -> {
replaceFragment(RecentTransactionsFragment.Companion.newInstance(),true,R.id.container)
}
R.id.item_recent_transactions -> {
replaceFragment(RecentTransactionsFragment.Companion.newInstance(), true, R.id.container)
}
R.id.item_about_us -> {
showAboutUs()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.mifos.mobile.cn.ui.utils

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.widget.Toast
import org.mifos.mobile.cn.R

class NetworkChangeReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val connectivityManager = context
.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetworkInfo = connectivityManager.activeNetworkInfo
if (activeNetworkInfo == null) Toast.makeText(context, context.getString(R.string.no_internet_connection),
Toast.LENGTH_LONG).show()
}
}

0 comments on commit 33235e9

Please sign in to comment.