diff --git a/README.md b/README.md index 71ae2b3..c15b6d2 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ allprojects { Add the dependency ``` dependencies { - implementation 'com.github.p32929:OfficeAbout:1.0.0.3' + implementation 'com.github.p32929:OfficeAbout:1.0.0.4' } ``` diff --git a/officeaboutlib/src/main/java/p32929/officeaboutlib/Activities/OfficeAboutActivity.java b/officeaboutlib/src/main/java/p32929/officeaboutlib/Activities/OfficeAboutActivity.java index 7552d24..db6eafa 100644 --- a/officeaboutlib/src/main/java/p32929/officeaboutlib/Activities/OfficeAboutActivity.java +++ b/officeaboutlib/src/main/java/p32929/officeaboutlib/Activities/OfficeAboutActivity.java @@ -69,90 +69,80 @@ public void onJsonDataReceived(final OfficeInfo officeInfo) { members.addAll(officeInfo.getMembers()); adapter.notifyDataSetChanged(); - if (officeInfo.getOfficeLogoUrl().isEmpty()) { - imageViewOfficeLogo.setVisibility(View.GONE); - } else { - imageViewOfficeLogo.setVisibility(View.VISIBLE); - Picasso.get().load(officeInfo.getOfficeLogoUrl()).into(imageViewOfficeLogo); - } - - if (officeInfo.getOfficeLogoUrl().isEmpty()) { - imageViewGooglePlay.setVisibility(View.GONE); - } else { - imageViewGooglePlay.setVisibility(View.VISIBLE); - imageViewGooglePlay.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + Picasso.get().load(officeInfo.getOfficeLogoUrl()).into(imageViewOfficeLogo); + + imageViewGooglePlay.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (isAvailable(officeInfo.getGooglePlayUrl())) { Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(officeInfo.getGooglePlayUrl())); startActivity(browse); + } else { + Toast.makeText(OfficeAboutActivity.this, "URL is not provided yet", Toast.LENGTH_SHORT).show(); } - }); - } - - if (officeInfo.getOfficeLogoUrl().isEmpty()) { - imageViewFacebook.setVisibility(View.GONE); - } else { - imageViewFacebook.setVisibility(View.VISIBLE); - imageViewFacebook.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + } + }); + + imageViewFacebook.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (isAvailable(officeInfo.getFacebookUrl())) { Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(officeInfo.getFacebookUrl())); startActivity(browse); + } else { + Toast.makeText(OfficeAboutActivity.this, "URL is not provided yet", Toast.LENGTH_SHORT).show(); } - }); - } - - if (officeInfo.getOfficeLogoUrl().isEmpty()) { - imageViewGroup.setVisibility(View.GONE); - } else { - imageViewGroup.setVisibility(View.VISIBLE); - imageViewGroup.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + } + }); + + imageViewGroup.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (isAvailable(officeInfo.getGroupUrl())) { Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(officeInfo.getGroupUrl())); startActivity(browse); + } else { + Toast.makeText(OfficeAboutActivity.this, "URL is not provided yet", Toast.LENGTH_SHORT).show(); } - }); - } - - if (officeInfo.getOfficeLogoUrl().isEmpty()) { - imageViewYoutube.setVisibility(View.GONE); - } else { - imageViewYoutube.setVisibility(View.VISIBLE); - imageViewYoutube.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + } + }); + + imageViewYoutube.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (isAvailable(officeInfo.getYoutubeUrl())) { Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(officeInfo.getYoutubeUrl())); startActivity(browse); + } else { + Toast.makeText(OfficeAboutActivity.this, "URL is not provided yet", Toast.LENGTH_SHORT).show(); } - }); - } - - if (officeInfo.getOfficeLogoUrl().isEmpty()) { - imageViewGithub.setVisibility(View.GONE); - } else { - imageViewGithub.setVisibility(View.VISIBLE); - imageViewGithub.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + } + }); + + imageViewGithub.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (isAvailable(officeInfo.getGithubUrl())) { Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(officeInfo.getGithubUrl())); startActivity(browse); + } else { + Toast.makeText(OfficeAboutActivity.this, "URL is not provided yet", Toast.LENGTH_SHORT).show(); } - }); - } - - if (officeInfo.getOfficeLogoUrl().isEmpty()) { - imageViewWeb.setVisibility(View.GONE); - } else { - imageViewWeb.setVisibility(View.VISIBLE); - imageViewWeb.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { + } + }); + + imageViewWeb.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (isAvailable(officeInfo.getWebUrl())) { Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(officeInfo.getWebUrl())); startActivity(browse); + } else { + Toast.makeText(OfficeAboutActivity.this, "URL is not provided yet", Toast.LENGTH_SHORT).show(); } - }); - } + } + }); + swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setEnabled(false); @@ -166,4 +156,16 @@ public void onError(String error) { } }).execute(); } + + private boolean isAvailable(String something) { + if (something == null) { + return false; + } else { + if (something.isEmpty()) { + return false; + } else { + return true; + } + } + } } diff --git a/officeaboutlib/src/main/res/layout/activity_office_about.xml b/officeaboutlib/src/main/res/layout/activity_office_about.xml index 49726a6..ba6ab2f 100644 --- a/officeaboutlib/src/main/res/layout/activity_office_about.xml +++ b/officeaboutlib/src/main/res/layout/activity_office_about.xml @@ -32,6 +32,7 @@ android:layout_width="match_parent" android:layout_height="175dp" android:adjustViewBounds="true" + android:layout_marginBottom="8dp" android:scaleType="centerInside" />