From 9e59187ae0f386cb7e97e46c6ae892aabfff2bc8 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Wed, 21 Feb 2018 15:05:38 +0100 Subject: [PATCH] Handle invalid WIF files --- .../apps/abit/ImportIdentitiesFragment.kt | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/ch/dissem/apps/abit/ImportIdentitiesFragment.kt b/app/src/main/java/ch/dissem/apps/abit/ImportIdentitiesFragment.kt index 5cbdf4e..29a4fce 100644 --- a/app/src/main/java/ch/dissem/apps/abit/ImportIdentitiesFragment.kt +++ b/app/src/main/java/ch/dissem/apps/abit/ImportIdentitiesFragment.kt @@ -25,12 +25,12 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button - -import com.h6ah4i.android.widget.advrecyclerview.decoration.SimpleListDividerDecorator - import ch.dissem.apps.abit.adapter.AddressSelectorAdapter import ch.dissem.apps.abit.service.Singleton import ch.dissem.bitmessage.wif.WifImporter +import com.h6ah4i.android.widget.advrecyclerview.decoration.SimpleListDividerDecorator +import org.ini4j.InvalidFileFormatException +import org.jetbrains.anko.longToast /** * @author Christian Basler @@ -39,8 +39,12 @@ class ImportIdentitiesFragment : Fragment() { private lateinit var adapter: AddressSelectorAdapter private lateinit var importer: WifImporter - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = - inflater.inflate(R.layout.fragment_import_select_identities, container, false) + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View = + inflater.inflate(R.layout.fragment_import_select_identities, container, false) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -48,17 +52,29 @@ class ImportIdentitiesFragment : Fragment() { val wifData = arguments.getString(WIF_DATA) val bmc = Singleton.getBitmessageContext(activity) - importer = WifImporter(bmc, wifData) + try { + importer = WifImporter(bmc, wifData) + } catch (e: InvalidFileFormatException) { + longToast(R.string.invalid_wif_file) + activity.finish() + return; + } + adapter = AddressSelectorAdapter(importer.getIdentities()) - val layoutManager = LinearLayoutManager(activity, - LinearLayoutManager.VERTICAL, - false) + val layoutManager = LinearLayoutManager( + activity, + LinearLayoutManager.VERTICAL, + false + ) val recyclerView = view.findViewById(R.id.recycler_view) recyclerView.layoutManager = layoutManager recyclerView.adapter = adapter - recyclerView.addItemDecoration(SimpleListDividerDecorator( - ContextCompat.getDrawable(activity, R.drawable.list_divider_h), true)) + recyclerView.addItemDecoration( + SimpleListDividerDecorator( + ContextCompat.getDrawable(activity, R.drawable.list_divider_h), true + ) + ) view.findViewById