Призма 5:
public abstract class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual bool SetProperty<T>(ref T storage,
T value,
[CallerMemberName] string propertyName = null)
{
if (object.Equals(storage, value)) return false;
storage = value;
this.OnPropertyChanged(propertyName);
return true;
}
protected void OnPropertyChanged(string propertyName)
{
var eventHandler = this.PropertyChanged;
if (eventHandler != null)
{
eventHandler(this, new PropertyChangedEventArgs(propertyName));
}
}
protected void OnPropertyChanged<T>(Expression<Func<T>> propertyExpression)
{
var propertyName = PropertySupport.ExtractPropertyName(propertyExpression);
this.OnPropertyChanged(propertyName);
}
}
public static class PropertySupport
{
public static string ExtractPropertyName<T>(Expression<Func<T>> propertyExpression)
{
if (propertyExpression == null)
{
throw new ArgumentNullException("propertyExpression");
}
var memberExpression = propertyExpression.Body as MemberExpression;
if (memberExpression == null)
{
throw new ArgumentException("The expression is not a member access expression.", "propertyExpression");
}
var property = memberExpression.Member as PropertyInfo;
if (property == null)
{
throw new ArgumentException("The member access expression does not access a property.", "propertyExpression");
}
var getMethod = property.GetMethod;
if (getMethod.IsStatic)
{
throw new ArgumentException("The referenced property is a static property.", "propertyExpression");
}
return memberExpression.Member.Name;
}
}
Ну, я нашел комментарий полезным и придумал это, чтобы решить мою вторую проблему.
val isAppInstalled = appInstalledOrNot("com.microsoft.office.officelens")
if (isAppInstalled)
{
//This intent will help you to launch if the package is already installed
Toast.makeText(this@ScrollingActivity, "Its toast at if!", Toast.LENGTH_SHORT).show()
val LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.microsoft.office.officelens")
startActivityForResult(LaunchIntent, IMAGE_PICK_CODE)
}
else
{
Toast.makeText(this@ScrollingActivity, "else executed!", Toast.LENGTH_SHORT).show()
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.microsoft.office.officelens"))
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivityForResult(intent, IMAGE_PICK_CODE)
}
Эта функция позволяет вам проверить, установлено приложение или нет
private fun appInstalledOrNot(uri:String):Boolean {
val pm = getPackageManager()
try
{
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES)
return true
}
catch (e:PackageManager.NameNotFoundException) {}
return false
}